The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search

Trail: Getting Started
Lesson: The "Hello World" Applet

## Running an Applet

> The bold lines of the following listing comprise the <APPLET> tag that includes the "Hello World" applet in an HTML page.

> >     <HTML>
> >     <HEAD>
> >     <TITLE> A Simple Program </TITLE>
> >     </HEAD>
> >     <BODY>

> >     Here is the output of my program:
> >     <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
> >     </APPLET>
> >     </BODY>
> >     </HTML>

> The above `<APPLET>` tag specifies that the browser should load the class whose compiled code is in the file named `HelloWorld.class`. The browser looks for this file in the same directory as the HTML document that contains the tag.

> When the browser finds the class file, it loads it over the network, if necessary, onto the computer the browser is running on. The browser then creates an instance of the class. If you include an applet twice in one page, the browser loads the class file once and creates two instances of the class.

> The `WIDTH` and `HEIGHT` attributes are like the same attributes in an `<IMG>` tag: They specify the size in pixels of the applet's display area. Most browsers do not let the applet resize itself to be larger or smaller than this display area. For example, every bit of drawing that the "Hello World" applet does in its `paint` method occurs within the 150x25-pixel display area that the above `<APPLET>` tag reserves for it.

> For more information on the `<APPLET>` tag, see Using the APPLET Tag.

| Start of Tutorial > Start of Trail > Start of Lesson | Search