• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Content Pane, getGraphics() and paint() problem

 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link Rob, i will try and let you know.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic