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
import java.awt.Graphics;
import java.applet.Applet;
public class LifeTest extends Applet
{
public void init()
{
System.out.println("init(): applet started");
}
public void start()
{
System.out.println("start(): applet activated");
}
public void paint(Graphics g)
{
System.out.println("paint(): applet running");
}
public void stop()
{
System.out.println("stop(): applet inactivated ");
}
public void destroy()
{
System.out.println("destroy(): applet destroyed");
}
}
2nd Program: HTML Program – Life.html
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.
thanks
???nice
bole to jakass life cycle bataya tune mamu
Tq its very useful and easily understandable one :)
Thanks again thank I happy
its wrong in applet life cycle first called public final void set stub(AppletStub as) method
very nice life cycle of applet its very useful
Thank you for the nice flow of applet lifecycle:-)
very nice
it is very useful for us….so thanks..
Thanx.
Its very helpfull note for me…..
So I again thanxx…
Thanks.
Thank you so much….. :-)
nice…
thanks
Thanks sir 4r explain
Thanks…
no thanks
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
Check the spelling of init() method you have written.
tnx…..
Thnx
Thanks
Thank you…