Methods of the Applet Class


 

Method

When the method is called, and its purpose

public void init()

Invoked when the applet is loaded.

Typical actions include: initializing instance
variables, GUI components, loading of sounds,
or images, creation of threads.

public void start()

Invoked after init(), and whenever the browser
returns to the web page on which applet resides.

Actions include starting anything that would be stopped
when the browser leaves the web page, such as
animations.

public void paint( Graphics g )

Invoked after init() completes, and start() has started.
Invoked automatically whenever applet needs to be
repainted, such as when the applet becomes uncovered
after the web page was obscured by some other window.

Also invoked by repaint(), after it clears the
effects of the previous
paint() invocation.

public void stop()

Invoked when the applet should stop executing, typically
when the browser leaves the web page on which the
applet resides.

Actions include stopping animations and threads.

public void destroy()

Invoked when the applet is being removed from memory,
typically when the browser terminates.

All active threads should be terminated, at this point.

This method is used to set the size of the applet at execution time (rather than at the time that the applet's web page is defined).

Imagine that we beefed up our RandomlyColoredBoard applet to include a TextField in which the user could specify NUM, where it is a NUM X NUM board. If we want each square to remain 40 pixels, then we can resize the applet (within limits) in response to the integer value of the TextField.