Tuesday, 29 November 2016

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



1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete