Applet Life Cycle

Applet Life Cycle


Using Applet Life Cycle methods

With this knowledge of applets, let us write a small applet to understand the syntax of developing an applet. Let us start from life cycle methods.

As you can guess, two programs exist, one applet (LifeTest.java) and one HTML (Life.html) file.

1st Program: Applet program – LifeTest.java

2nd Program: HTML Program – Life.html


Applet Life Cycle
Screenshot of Life.html of Applet Life Cycle

Compilation and Execution

In compilation, no difference with applets; only execution differs.

Compilation C:\snr\way2java\applets> javac LifeTest.java
Execution C:\snr\way2java\applets> appletviewer Life.html

As discussed earlier, the above HTML file can be run in two ways. Anyhow, let us run this with appletviewer as println() methods do not work in a browser. We use browser in later applets.

All the five methods of Applet Life Cycle are included in the above applet program and stuffed with just println() statements; the best way to understand which method is called when. When applet is destroyed, the browser calls stop() and destroy() methods. The output will be obtained at DOS prompt. The above screenshot shows clearly.

20 thoughts on “Applet Life Cycle

  1. praveen

    Thanx for ur explanation sir it is very easy to learn sir i have a doubt

    In the above ‘LifeTest.java’ when am executing this file am not writing ‘init()’ method even though it is executing remaining methods but in ur explanation ‘init()’ method starts ‘start()’ method but how ‘start()’ method will called with out writing ‘init()’ method? please clear me sir

Leave a Reply

Your email address will not be published. Required fields are marked *