Adding Java Applets to the Page

Java applets are self-contained programs written in the Java programming language, that can be placed inline on a web page just like a graphic. There are lots of Java applets available on the Web for free from Java library sites such as the JavaBoutique ((http://javaboutique.internet.com).

Most Java applet instructions require that you add the applet to the page using the handy <applet> tag (made just for the job!). However, the HTML 4.0 Spec recommends that applets be added using the <object> tag instead, although this is problematic in that some browsers don’t recognize the <object> tag when used with Java. In this section, we will focus on the <applet> method.

The <applet> tag is a container for any number of parameter (<param>) tags. The following is an example of how an <applet> tag for a game might look:

<APPLET CODEBASE=class CODE="Wacky.class" WIDTH=300 HEIGHT=400>
<PARAM NAME="Delay" VALUE="250">
<PARAM NAME="Time" VALUE="120">
<PARAM NAME="PlaySounds" VALUE="YES">
</APPLET>

The opening applet tag contains a number of standard attributes:

code

Tells the browser which applet will be used. Applets end with the suffix .class or .jar. This attribute is required.

codebase

This tells the browser in which directory to find the applets. If the applets are in the same directory as the page, the codebase attribute is not necessary.

width and height

These specify the pixel dimensions of the “window” the applet will occupy. These attributes are required ...

Get Web Design in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.