Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in paint method.

 
Ali Haider
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having problem when drawing on the applet. I'm using an image for drawing, means using image of the size of the applet for drawing. When I draw anything at the image, if I do the drawing in paint method then it works else not. Don't know whats the problem with it.
Reply soon
Thankx in advance
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was under the (perhaps incorrect) impression that painting only can be done in the paintmethod. So painting should only be done there. If you call a method during execution of the paintmethod and do some painting in that method, that will be fine, too!
/Kaspar
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason you are having this problem is because of the repaint() -> update() -> paint() cycle that happens when the applet is repainted. The only thing that the applet 'remembers' to paint when the screen is refreshed is code in these methods, or code in methods called by these... a good rule of thumb is to keep all your painting code in the paint() method, or methods that are called by the paint method... anything else ( such as painting done in event handlers ) disappears when the screen is refreshed.

HTH,
-Nate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic