• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Content Pane, getGraphics() and paint() problem

 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link Rob, i will try and let you know.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic