We can draw a rectangle using the drawRect( ) method. This method takes four arguments. The first two represent the x and y coordinates of the top left corner of the rectangle, and the remaining two represent the width and the height of the rectangle.


We can draw a solid box by using the method fillRect( ). This also takes four parameters (as drawRect) corresponding to the starting point, the width and the height of the rectangle.

drawRoundRect and fillRoundRect

We can also draw rounded rectangles (which are rectangles with rounded edges), using the methods drawRoundRect( ) and fillRoundRect( ). These two methods are similar to drawRect( ) and fillRect( ) except that they take two extra arguments representing the width and height of the angle of corners. These extra parameters indicate how much of corners will be rounded.


1 (1)

Program Source

import java.applet.Applet;
import java.awt.Graphics;

public class Javaapp extends Applet {
    public void paint(Graphics g) {
        g.drawRect(10, 10, 70, 70);
        g.fillRect(100, 10, 70, 70);
        g.drawRoundRect(10, 100, 70, 70,15,15);
        g.fillRoundRect(100, 100, 70, 70,15,15);

Leave a Comment