Need help with simple graphics drawing application
1 posts in topic
Flat View  Flat View

Posted By:   Mike_McElfresh
Posted On:   Sunday, November 11, 2001 09:26 AM

I have a simple application with 4 radio buttons used to draw simple geometric shapes on a JPanel. I want to be able to display all the shapes on the panel at the same time. Whenever I click the button to draw a second shape, the panel clears and I lose my previous shape. Thanks!

Re: Need help with simple graphics drawing application

Posted By:   Scott_Stanchfield  
Posted On:   Thursday, November 15, 2001 03:58 PM

If you want to keep the stuff you've already drawn, you have two choices:

  1. Keep track of the shapes drawn and repaint them in the paint() method
  2. 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.

About | Sitemap | Contact