Thursday, November 15, 2001 03:58 PM
If you want to keep the stuff you've already drawn, you have two choices:
- Keep track of the shapes drawn and repaint them in the paint() method
- Override the update(Graphics g) method to just call paint(g)
The first alternative is really the right one. The problem with the second is that if something "damages" your drawing area (like another window being moved over it) the previous shapes will not be redrawn.
Of course another alternative is to draw everything to an offscreen buffer and dump that buffer to the screen in your paint method. To do this, just create a new AWT Image object (use Component.createImage(...)), get its Graphics object to do your drawing, then use the Graphics object passed into the paint() method to dump the Image.