Drawing Things
The class Graphics defines most operations for drawing
on the screen (or on off-screen images).
All operations only have effect within the applet's window.
(They are automatically clipped.)
The operations use properties from the graphic context of the component,
like the color and font.
Some commonly used methods are:
- drawString(String s, int x, int y)
- draws a string at a certain position.
This was used in the "hello world" applet.
- drawLine(int x1, int y1, int x2, int y2)
- draws a line between two endpoints.
- drawRect(int x, int y, int width, int height)
- draws an open rectangle with given upper lefthand corner, width and height.
- drawImage(Image img, int x, int y, ImageObserver observer)
- draws an image with given upper lefthand corner. It interacts with an
imageobserver for loading the image, because drawing can start before an
image is completely loaded.
Graphics is an abstract class.
Some methods are implemented, but others like
drawRoundRect and drawOval are not.