Java Reference
In-Depth Information
2.
The browser creates an instance of the Applet class, invoking the
default constructor.
3.
The applet is displayed in the Web page, with the location and size of
the applet determined by the HTML.
4.
The browser invokes the init() method on the applet.
5.
The browser invokes the start() method on the applet.
6.
The browser invokes the paint() method on the applet.
7.
The applet is now live and running within the Web page.
8.
The browser calls paint() whenever the applet needs to repaint itself.
9.
The browser invokes the stop() method when the user leaves the Web
page or the applet is about to be destroyed.
10.
The browser invokes the destroy() method just before destroying the
applet.
Notice that the browser communicates with the applet by invoking methods
on the applet. The methods invoked by the browser are defined in the Applet
class, and your Applet class can override any of these methods to perform
whatever tasks it wants to.
Let's look at the five methods that the browser invokes on your applet.
public void init(). The first method invoked on the applet when it is ini-
tially instantiated. This is your chance to perform any initialization, such
as locating resources or preparing event handlers.
public void start(). Invoked by the browser to inform the applet that it
should start executing. The start() method is called right after the init()
method, and is also called when the page is revisited. This is a good time
to start any threads or other tasks like displaying animation or playing
sound.
public void stop(). Invoked by the Web browser to inform the applet that
it should stop executing. The stop() method is called right before the
destroy() method is invoked, and also when a user leaves the Web page.
Typically, anything you started in the start() method is stopped in the
stop() method.
public void destroy(). Invoked by the Web browser to inform the applet
that it is about to be destroyed (in other words, garbage collected). Typi-
cally, any resources allocated in the init() method are freed in the
destroy() method.
public void paint(Graphics g). Invoked immediately after the start()
method, and also any time the applet needs to repaint itself in the
Search WWH ::




Custom Search