Program to display life cycle of an Applet.

This program demonstartes the life cycle methods of an Applet. During execution of an applet it goes through different stages these are init( ), start( ), paint( ), stop( ) and destroy( ). When you run this program it will call init( ), start( ) and paint( ) method as shown in output. The remaining two methods stop( ) and destroy( ) are called when applet stops or when it is destroyed respectively.


PROGRAM
import java.applet.Applet;
import java.awt.Graphics;

public class AppletLifeCycleDemo extends Applet {
 
 String msg = "";
 
 public void init() {
  
  msg += "init( ) -> ";
 }
 
 public void start() {
  
  msg += "start( ) -> ";
 }
 
 public void paint(Graphics g) {
  
  msg += "paint( )";
  g.drawString(msg, 20, 20);
 }
 
 public void stop() {
  
  msg += " -> stop( )";
 }
 
 public void destroy() {
  
  msg += "-> destroy( )";
 }
}

/*
<APPLET CODE="AppletLifeCycleDemo.class" HEIGHT="200" WIDTH="200" >
</APPLET>
*/
OUTPUT
C:\>javac AppletLifeCycleDemo.java 
C:\>appletviewer AppletLifeCycleDemo.java



Comments

Popular posts from this blog

Develop an Android application to display “Hello World!” on screen

Program to design an applet which draws a circle (having color BLUE) inside a triangle (having color YELLOW)

Build a Simple Android App to Display Student Details