Using Java Applets

David Wallace Croft


What are Applets?

Applets are little programs that you can embed in your web pages.

Applets are "live".
Example: a multiplayer arcade game interface.

Applets are secure. They cannot read from or write to your hard drive while you are using them.

Adding an Applet

To add an applet to your web page, you can simply add an applet HTML tag such as the following.
An applet would be here.

It's Like the Image Tag

The HTML "applet" tag shares many attributes in common with the HTML "image" tag.

Notice that, like a graphics image, the applet can be loaded from a different server. In the above example, it is being loaded from

Special Applet Attributes

The CODE applet tag attribute gives the name of the main applet class to be loaded. This class, once loaded, will call and load additional classes as needed.

The CODEBASE specifies the server and directory from which the classes are loaded. The codebase attribute is optional; if it is not specified, the browser will assume that the classes should be loaded from the same URL (server and directory) as the web page.

The optional ARCHIVE attribute provides a list of pre-compressed files including classes, multimedia, and data files that your applet may need. The archive files are downloaded and checked first before individual files are sought from the server.


Some applets need additional parameters specified to customize operation. These parameters are akin to providing command-line arguments to a program. They are provided using the <PARAM> tag in the form of name/value pairs.

  <PARAM NAME="music"     VALUE="">
  <PARAM NAME="pausetime" VALUE="10"       >
  <PARAM NAME="slide0"    VALUE="me.gif"   >
  <PARAM NAME="slide1"    VALUE="bear.jpg" >
  <PARAM NAME="slide2"    VALUE="dog.gif"  >


If your applet does not work, there could be a number of problems.

To check if your applet is crashing in Netscape Navigator, click on "Communicator" and then "Java Console" to view the error output.

Sample Applet

Embedded in this web page is an applet which you put in your HTML pages right away. In Netscape Navigator, click on "View" and then "Page Source" to copy the applet tag and then paste it into your pages.

Copyleft 1997 David Wallace Croft
Posted 1997-10-15