The life cycle of the applet has the following stages:
The appletviewer loads and creates the specified class.
The applet initializes itself.
The applet starts running.
When finished the applet is destroyed.
The applet always receives an init()
method first and then a start()
and
paint()
call (Note: This may happen asynchronously! i.e. at the same time).
java.applet Class Applet java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Panel | +--java.applet.Applet
To use the java.applet.Applet
class to make a useful applet you must create a subclass of
Applet. To do this, you must override some (or all) of the following methods:
init()
- This method 'sets-up' the applet, called once when the applet is first
initialized. Use this method to set up the display of the applet, set colours etc.
start()
- Called whenever the applet is visited, i.e. the applet starts running
again. You could use this method to start up an animation that stops when the applet is minimised. This method would be called
when the web browser has been restored after being minimised.
stop()
- Called when the applet is no longer active (e.g. minimized)
paint()
- This method is called whenever the appearance of the applet is required to be
updated, such as when the applet is being maximized from a minimized state. The appearance needs to be updated. It is also possible for
the programmer to call this method. This method does nothing by default, you must write the code.
destroy()
- Called when the applet is discarded. This method should perform any closing
down tasks that you would wish to perform, such as closing connections to databases, etc.
© 2006
Dr. Derek Molloy
(DCU).