by Dinesh Thakur

The Graphics class provides different methods for drawing shapes such as lines, rectangles and ovals. Table shows the methods that are used to draw shapes. Each drawing method takes.

                                       Methods in the Graphics Class

 

Method

Description

public void drawLine( int x1, int y1, int x2, int y2 )

Draws a line between the point (xl, yl) and the point (x2, y2).

public void drawRect( int x, int y, int width, int height)

Draws a bordered rectangle of specified 'width' and 'height' starting at the point 'x' and 'y'.

Public void fillRect(int x, int y, int width, int height)

Fills a rectangle of specified 'width' and 'height' starting from the position 'x' and 'y'.

public void clearRect( int x, int y. int width, int height)

Draws a filled rectangle of specified 'width' and 'height' starting from the position 'x' and 'y' with the current background colour.

public void drawRoundRect( int x, int y,int width. int height, int arcWidth, int arcHeight )

Draws a rectangle with rounded comers with the specified 'width' and 'height' starting from the position 'x' and'y'. The shape of the rounded comers are specified by parameters 'arcWidth' and 'arcHeight.

Pubic void fillRoundRect(int x, int y,int width, int height, int arcWidth. Int arcHeight )

Draws a rectangle with rounded comers with the specified 'width' and 'height' starting from the position 'x' and'y'. Rounded comers are specified with the 'arcWidth' and 'arcHeight'.

Public void draw3DRect( int x, int y, int width, int height, boolean b )

Draws a three-dimensional rectangle with specified 'width' and 'height' starting from the position 'x' and 'y'.

Public void fill3DRect( int x, int y, int width, int height, boolean b )

Draws a three-dimensional filled rectangle with specified 'width' and 'height' starting from the position 'x' and 'y'.

public void drawOval( int X, int y, int width, int height)

Draws an oval with specified 'width' and 'height' starting with the location 'x' and 'y'.

Public void fillOval(int x, int y, int width,int height)

Draws a filled oval with specified 'width' and 'height' starting with the location 'x' and 'y'.

 

the width and height of the shape as parameters" These parameters should be non-negative" These methods do not return any value and instead draw the shapes with the current colour of the Graphics object.