Applet lifecycle
Applet Lifecycle An applet is a Java program that is embedded in a web browser. It acts as a bridge between the browser and the underlying operating system....
Applet Lifecycle An applet is a Java program that is embedded in a web browser. It acts as a bridge between the browser and the underlying operating system....
An applet is a Java program that is embedded in a web browser. It acts as a bridge between the browser and the underlying operating system.
The lifecycle of an applet is divided into three main stages: initialization, execution, and termination.
Initialization:
An applet is loaded into memory by the web browser.
The browser sets up a dedicated thread to handle the applet's events.
The applet receives the "init" event and is initialized.
Execution:
The applet's event loop is started, which allows it to receive events from the browser and the operating system.
The applet can perform various tasks, such as listening for user input, interacting with the underlying system, or accessing resources.
The applet receives the "run" event and starts executing its main code.
Termination:
When the user closes the browser or navigates away from the applet, the "stop" event is fired.
The applet stops executing and is removed from memory.
The browser also sends the "unload" event to the applet, indicating that it is being closed.
Examples:
Consider an applet that displays a countdown timer.
When the user clicks on a button in an applet, the applet receives the "action" event.
An applet listening to a network socket can receive incoming data and process it.
When the browser is closed, the applet receives the "stop" event and stops its execution