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

  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

Post a Comment

Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to draw Smiley in Applet