aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Content Pane, getGraphics() and paint() problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Content Pane, getGraphics() and paint() problem" Watch "Content Pane, getGraphics() and paint() problem" New topic
Author

Content Pane, getGraphics() and paint() problem

Rameshwar Soni
Ranch Hand

Joined: Feb 03, 2011
Posts: 247
I had asked the same question at stackoverflow but didn't got any useful tips. The only difference is that here I have changed the JApplet to JFrame. Stackoverflow Link

What I need to do in program :There are total 2 buttons Circle and Square. When a user clicks on Circle button, the counter should count the number of times the Circle button has been clicked and draw that many circle. Thats fine. Now when the user clicks on Square button same thing should happen i.e. counting and drawing the squares and it works fine.

Now when again the user clicks on Circle button then the problem is that the previous circles drawn gets disappeared and it again starts from one.

Here's the code.

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2225
    
    8
Don't override the paint() method to do painting.

Painting is done by overriding the paintComponent() method of a JPanel. Then you add the panel to the frame.

See Custom Painting Approaches for an example.
Rameshwar Soni
Ranch Hand

Joined: Feb 03, 2011
Posts: 247
Thanks for the link Rob, i will try and let you know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Content Pane, getGraphics() and paint() problem