CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Applets

Applets
Introduction
The Applet

When the applet is loaded, the Web browser creates an instance of the applet by invoking the applet's no-arg constructor. The browser uses the init, start, stop, and destroy methods to control the applet. By default, these methods do nothing. To perform specific functions, they need to be modified in the user's applet so that the browser can call your code properly.

public class MyApplet extends java.applet.Applet {
  ...
  /** The no-arg constructor is called by the browser when the Web
      page containing this applet is initially loaded, or reloaded
    */
  public MyApplet() {
    ...
  }

  /** Called by the browser after the applet is loaded
    */
  public void init() {
    ...
  }

  /** Called by the browser after the init() method, or
     every time the Web page is visited
    */
  public void start() {
    ...
  }

  /** Called by the browser when the page containing this
     applet becomes inactive
     */
  public void stop() {
    ...
  }

  /** Called by the browser when the Web browser exits */
  public void destroy() {
    ...
  }

  /** Other methods if necessary... */
}

Previous | The Applet | History | Security | Inheritance | The JApplet | Writing applet | Next