0% found this document useful (0 votes)
86 views2 pages

Applet Life Cycle

When an applet runs in a web browser, it goes through four stages: initialization, start, stop, and destroy. These stages correspond to the applet methods init(), start(), stop(), and destroy(). The init() method performs initialization and is called once. The start() method begins processing and may be called multiple times. The stop() method suspends execution when the page is not visible. The destroy() method cleans up resources and is called once when the browser exits.

Uploaded by

Ashish Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views2 pages

Applet Life Cycle

When an applet runs in a web browser, it goes through four stages: initialization, start, stop, and destroy. These stages correspond to the applet methods init(), start(), stop(), and destroy(). The init() method performs initialization and is called once. The start() method begins processing and may be called multiple times. The stop() method suspends execution when the page is not visible. The destroy() method cleans up resources and is called once when the browser exits.

Uploaded by

Ashish Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Applet Life Cycle

When an applet is executed within the web browser, it goes through the four stages of its life cycle:
initialized, started, stopped and destroyed. These stages correspond to the applet methods init (),
start (), stop () and destroy () respectively.

• Public void init (): This method is used to perform any initialization that needed for the applet. It is
called automatically when the applet is first loaded into the browser and is called only once during the
life cycle of the applet. In this method, we generally perform startup activities such as adding GUI
components; loading resources such as images, audio, font; creating threads; and getting string
parameter values from the APPLET tag in the HTML page.

• Public void start (): After the applet is loaded and initialized, the Java environment automatically calls
the start () method. It also called when the user returns to the HTML page that contains the applet after
browsing through other webpages. This method is used to start the processing for the applet. For
example, Action performed here might include starting an animation or starting other threads of
execution. Unlike the init () method, the start () method may be called more than once during the life
cycle of an applet.

• Public void stop (): This method is called automatically by the browser when the user moves off the
HTML page containing the applet. It is generally used to suspend the applet's execution so that it does
not take up system resources when the user is not viewing the HTML page or has quit the browser. For
example, Processor intensive activities such as animation, playing audio files or performing calculations
in a thread can be stopped which not visible to the user until the user returns to the page.

• Public void destroy (): This method called after the stop () method when the user exits the web
browser normally. This method is used to clean up resources allocated to the applet that is managed by
the local operating system. Like the init () method, it is called only once in the lifetime of the applet.

Public void paint(): The paint() method is used to redraw the output on the applet display area. The
paint () method executes after the execution of start() method and whenever the applet or browser is
resized.
Example:

Applet Life Cycle

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.*;
/*<applet code="AppletLifeCycle.class" width="350" height="150"> </applet>*/
public class AppletLifeCycle extends Applet{
public void init()
{ setBackground(Color.CYAN);

System.out.println("init() called");

public void start(){ System.out.println("Start() called"); }

public void paint(Graphics g){ System.out.println("Paint(() called"); }

public void stop() { System.out.println("Stop() Called"); }

public void destroy() { System.out.println("Destroy)() Called"); }}

You might also like