Monday, 17 February 2014

AN APPLET SKELETON

Java:Applet Skeleton

Most of the applets override a set of methods that controls its execution.

  • Four of these methods init( ), start( ), stop( ), and destroy( ) are defined by Applet.
  • paint( ), is defined by the AWT Component class.


These five methods can be assembled into the skeleton shown here: 


// An Applet skeleton.

import java.awt.*;
import javax.swing.*;
/*
<applet code="AppletSkel" width=300 height=100>
</applet>
*/

public class AppletSkel extends JApplet {
  // Called first.
  public void init() {
    // initialization
  }

  /* Called second, after init().  Also called whenever
     the applet is restarted. */
  public void start() {
    // start or resume execution
  }

  // Called when the applet is stopped.
  public void stop() {
    // suspends execution
  }

  /* Called when applet is terminated.  This is the last
     method executed. */
  public void destroy() {
    // perform shutdown activities
  }

  // Called when an applet's window must be restored.
  public void paint(Graphics g) {
    // redisplay contents of window
  }
}

Although this skeleton does not do anything,it can be compiled and run.When run,it generates the following window when viewed with an appletviewer:









3 comments :

  1. javac AppletSkel.java
    (no errors)
    java AppletSkel
    (But no answer)

    where and what to do ?

    ReplyDelete
    Replies
    1. run applet using "appletviewer AppletSkel.java " command

      Delete
  2. I think this is an informative post and it is very beneficial and knowledgeable. Therefore, I would like to thank you for the endeavors that you have made in writing this article. All the content is absolutely well-researched. Thanks... skeleton halloween costume sexy

    ReplyDelete