Graphics class

When we use the paint method as follows:

public void paint (Graphics g)

What happens is that paint creates an object from the Graphics class, which is called g. (Note that we could call it anything and sometimes programmers call it window etc.)

The Graphics class provides a range of methods which we can use with our object g.

This is a list with an explanation of the parameters

drawLine (int startX, int startY, int endX, int endY)

drawRect (int startX, int startY, int width, int height)

drawOval (int startX, int startY, int width, int height)

drawOval.jpg

drawArc (int startX, int startY, int width, int height, int startAngle, int arcAngle)

drawString ("string", int x, int y)

To use these we specify the object and the method like this

Note that if there are changes to parameters once the paint method is executed a 'repaint' is needed to update the Graphics object.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License