1

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 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

I am new to java applet design and when running it i get one problem that says "no main"

here is my code:

import java.applet.*;
import java.awt.*;
public class abhidev extends Applet {

    /** Initializes the applet abhidev */
    public void init() {
        try {
            setBackground(Color.cyan);

        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
    public void paint(Graphics g){
        try{
            g.drawString("this ais an applet window",10,30);
            showStatus("this is astatus window");
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

The applet class name is: abhidev.java.

1 Comment

This looks like a separate issue. Please post it as its own question by clicking the Ask Question button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.