Graphics Methods

These are just some of the methods that can be used in the paint(Graphics g) or paintComponent(Graphics g) methods to create designs and scenes.

clearRect(intx, inty, intwidth, intheight)
Clears the specified rectangle by filling it with the background color of the current drawing surface.

draw3DRect(intx, inty, intwidth, intheight, booleanraised)
Draws a 3-D highlighted outline of the specified rectangle.

drawArc(intx, inty, intwidth, intheight, intstartAngle, intarcAngle)
Draws the outline of a circular or elliptical arc covering the specified rectangle.

drawImage(Imageimg, intx, inty, ImageObserverobserver)
Draws as much of the specified image as is currently available.

drawImage(Imageimg, intx, inty, intwidth, intheight, ImageObserverobserver)
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.

drawLine(intx1, inty1, intx2, inty2)
Draws a line, using the current color, between the points (x1,y1) and (x2,y2) in this graphics context's coordinate system.

drawOval(intx, inty, intwidth, intheight)
Draws the outline of an oval.

drawPolygon(int[]xPoints, int[]yPoints, intnPoints)
Draws a closed polygon defined by arrays of x and y coordinates.

drawPolyline(int[]xPoints, int[]yPoints, intnPoints)
Draws a sequence of connected lines defined by arrays of x and y coordinates.

drawRect(intx, inty, intwidth, intheight)
Draws the outline of the specified rectangle.

drawRoundRect(intx, inty, intwidth, intheight, intarcWidth, intarcHeight)
Draws an outlined round-cornered rectangle using this graphics context's current color.

drawString(Stringstr, intx, inty)
Draws the text given by the specified string, using this graphics context's current font and color.

fill3DRect(intx, inty, intwidth, intheight, booleanraised)
Paints a 3-D highlighted rectangle filled with the current color.

fillArc(intx, inty, intwidth, intheight, intstartAngle, intarcAngle)
Fills a circular or elliptical arc covering the specified rectangle.

fillOval(intx, inty, intwidth, intheight)
Fills an oval bounded by the specified rectangle with the current color.

fillPolygon(int[]xPoints, int[]yPoints, intnPoints)
Fills a closed polygon defined by arrays of x and y coordinates.

fillRect(intx, inty, intwidth, intheight)
Fills the specified rectangle.

fillRoundRect(intx, inty, intwidth, intheight, intarcWidth, intarcHeight)
Fills the specified rounded corner rectangle with the current color.

setColor(Colorc)
Sets this graphics context's current color to the specified color.

Possible Colors: These colors can be used with the set color command.

Use Color. followed by the color name. i.e. g.setColor(Color.blue)

black

blue

cyan

darkGray

gray

green

lightGray

magenta

orange

pink

red

white

yellow

or you can create your own colour using red green blue values for your colour as follows

Color c = new Color(int red, int green, int blue)

Where the red, green, and blue values are between 0 and 255

Or if you want to set transparencies with a colour, you can add an alpha value.

Color c = new Color(int red, int green, int blue, int alpha)

Where the red, green, blue, and alpha values are between 0 and 255.

The closer the alpha value is to 255, the more solid the colour is. The closer to zero, the more transparent the colour is.

For more methods of the graphics object, check out

http://download.oracle.com/javase/1.5.0/docs/api/java/awt/Graphics.html