No. The Web browser is the main application. An applet is an object that the web browser uses.

An Example JApplet

An applet is an object that is used by another program, typically a Web browser. The Web browser is the application program and (at least conceptually) holds the main() method. The applet part of a Web page provides services (methods) to the browser when the browser asks for them.

An applet object has many instance variables and methods. Most of these are defined in the JApplet class. To access these definitions, your program should import javax.applet.JApplet and java.awt.*. Here is the code for a small applet. The name of the class is Poem and the name of the source file is

import javax.swing.JApplet;
import java.awt.*;

public class Poem extends JApplet
  public void paint ( Graphics gr )
    setBackground( Color.white );
    gr.drawString("Loveliest of trees, the cherry now", 25, 30);
    gr.drawString("Is hung with bloom along the bough,", 25, 50);
    gr.drawString("And stands about the woodland ride", 25, 70 );
    gr.drawString("Wearing white for Eastertide." ,25, 90);
    gr.drawString("--- A. E. Housman" ,50, 130);

The applet is compiled just like an application using javac This produces a bytecode file called Poem.class that can be used in a Web page. Here is what this applet does:

Not all browsers can run applets. If you see this, yours can not. You should be able to continue reading these lessons, however.

The applet is responsible for the white rectangle that is part of this page as presented by your Web browser. The size of the rectangle is given in the HTML that describes the entire Web page. This will be discussed later.

Note: If you don't see the white rectangle you may be using a browser that has applets disabled. Sometimes this is done for security reasons. Also, some firewalls block applets.


Look at the code for the class Poem. How many methods does it define?