tags:

views:

24

answers:

2

Hi,

I'm new to Java Applets. I have a problem while reloading the applet. When I resize the applet window or open some other application and then come back to the applet, the contents on the screen is redrawn. Basically my paint method is getting called. I want the contents of the paint method to be called only once. How can I accomplish this? Can anyone please help me with this?

Thanks in advance.

+3  A: 

You are misunderstanding how paint works - you have no real control over how many times it is called. What are you doing in the paint method that makes you think you only want to do it once and why is it a problem that it gets called again?

If you're worrying about flickering, then you might like to look at painting into a buffer. Code not directly related to painting should not be in the paint method. You can put other initialization logic in the applet's start method

oxbow_lakes
A: 

If you're putting initialization code into the paint method, you might think about putting it into the init or start methods instead.

The phrase you'd be looking for is applet lifecycle.

Rich Apodaca