• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Swing applet design paintComponent or repaint ?

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is an example of a swing applet which uses paintComponent. The paintComponent method is called almost non stop. I can prevent its executing by setting a flag which prevents the thread from continuing once it enters the paintComponent method - unless there is actually a change in the data.

However I believe there must be a design solution to this issue or perhaps just a better design which does not use paintComponet but instead calls repaint?? All the objects in paintComponet are native - no custom graphics.

Any advice please.

Thanks!

link to code snippet:
http://pastebin.com/f9BEPBc4
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code should be posted in this forum.

I don't understand the question.

super.paintComponent() should only ever be executed in the paintComponent() method if you are overriding the method.

repaint() is used to tell the component to repaint() itself when a property that controls the painting of the component is changed.
 
Robert Kennedy
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the response. I am trying to get a pointer on how to restructure this code so it does not use paint component.
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A few mistakes:
- paintComponent should remain protected. There's no need to make it coderanch.
- paintComponent misses the call to super.paintComponent(g).
- you're creating user interfaces and have complete business logic in the paintComponent method. That method's going to be called A LOT.

The paint methods should be used for just that - painting the component.
 
Robert Kennedy
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I made these changes based on your observations.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic