How can I extend the Graphics class to add a new drawing method?
Created Sep 28, 2001
Scott Stanchfield
If you'd like to create utility functions to paint different things, you can create a new class that you pass the graphics context to.
You're not supposed to extend it.
The AWT manager creates and passes Graphics objects to you to use to paint. It's the only thing that really knows how to set them up properly.
Suppose you wanted to draw a Dragon (fractal) you could create
public class Dragon {
public static void draw(Graphics g) {
g.draw...
}
}
and from your paint method
public void paint(Graphics g) {
Dragon.draw(g);
}
}