The
Appletclass provides a framework for applet execution, defining methods that the system calls when milestones occur. Milestones are major events in an applet's life cycle. Most applets override some or all of these methods to respond appropriately to milestones.
initMethodThe
initmethod is useful for one-time initialization that doesn't take very long. Theinitmethod typically contains the code that you would normally put into a constructor. The reason applets don't usually have constructors is that they aren't guaranteed to have a full environment until theirinitmethod is called. Keep theinitmethod short so that your applet can load quickly.
startMethodEvery applet that performs tasks after initialization (except in direct response to user actions) must override the
startmethod. Thestartmethod starts the execution of the applet. It is good practice to return quickly from thestartmethod. If you need to perform computationally intensive operations it might be better to start a new thread for this purpose.
stopMethodMost applets that override the
startshould also override thestopmethod. Thestopmethod should suspend the applet's execution, so that it doesn't take up system resources when the user isn't viewing the applet's page. For example, an applet that displays an animation should stop trying to draw the animation when the user isn't viewing it.
destroyMethodMany applets don't need to override the
destroymethod because theirstopmethod (which is called beforedestroy) will perform all tasks necessary to shut down the applet's execution. However, thedestroymethod is available for applets that need to release additional resources.
Note: Keep implementations of thedestroymethod as short as possible, because there is no guarantee that this method will be completely executed. The Java Virtual Machine might exit before a longdestroymethod has completed.