In detail, how do the applet life cycle methods init(), start(), paint(), stop(), and destroy() work?
The life cycle methods of an applet are init(), start(), stop(), and destroy(). While frequently grouped with the methods, the paint() method is not really part of the applet's life cycle. The method is just called by the browser whenever a part of the screen has become invalidated or in response to a programmer-generated repaint request. The update() method falls into the same category as paint().
As far as the other methods go:
- init() - called once when applet is loaded
- start() - called every time the page the applet is located on is loaded, after init() or after leaving the page and returning
- stop() - called every time the page the applet is located on is left
- destroy() - called when applet is unloaded
Use the start() / stop() method pair to deal with starting and stopping threads, as when the page isn't active it isn't nice to use up resources.
Don't rely on the destroy() method being called to free a crucial resource, in case the browser crashes.
I had heard that start() / stop() were called for iconifying and deiconifying, but a test with the latest browser versions shows they aren't called.