How can I extend the Graphics class to add a new drawing method?

Scott Stanchfield

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.

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.

Suppose you wanted to draw a Dragon (fractal) you could create

public class Dragon {
  public static void draw(Graphics g) {

and from your paint method

  public void paint(Graphics g) {