NOTE : The information provided here only describes the necessary HTML elements that allow pre-compiled HotJava applets to be added to your HTML documents. It does not describe how to actually write HotJava applets. Such information is well beyond the scope of this document. More information can be found about writing HotJava applets and how to obtain a copy of the HotJava browser and Java development kit from :

http://java.sun.com/

Also, Microsoft recently released their Java SDK, to complement their Visual J++ product. For more details, visit http://www.microsoft.com/java/

To add an applet to an HTML page, you need to use the <APPLET> HTML element.

<APPLET CODE="Applet.class" WIDTH=200 HEIGHT=150>
</APPLET>

This tells the viewer or browser to load the applet whose compiled code is in Applet.class (in the same directory as the current HTML document), and to set the initial size of the applet to 200 pixels wide and 150 pixels high. (The <APPLET> element supports standard image type attributes - see below).

Below is a more complex example of an <APPLET> element:

<APPLET CODEBASE="http://java.sun.com/JDK-prebeta1/applets/ NervousText" CODE="NervousText.class"
width=400 height=75 align=center>
<PARAM NAME="text" VALUE="This is the Applet Viewer.">
<BLOCKQUOTE>
<HR>
If you were using a Java-enabled browser, you would see dancing text instead of this paragraph.
<HR>
</BLOCKQUOTE>
</APPLET>

This tells the viewer or browser to load the applet whose compiled code is at the URL http://java.sun.com/JDK-prebeta1/applets/NervousText/NervousText.class, to set the initial size of the applet to 400x75 pixels, and to align the applet in the centre of the line. The viewer/browser must also set the applet's "text" attribute (which customizes the text this applet displays) to be "This is the Applet Viewer." If the page is viewed by a browser that can't execute applets written in the Java Programming Language, then the browser will ignore the <APPLET> and <PARAM> elements, displaying the HTML between the <BLOCKQUOTE> elements.

The complete syntax for the <APPLET> element is as follows :

<APPLET
[CODEBASE = URL]
[CODE = appletFile]
[ARCHIVE = compressed file]
[ALT = alternateText]
[NAME = appletInstanceName]
[WIDTH = pixels]
[HEIGHT = pixels]
[ALIGN = alignment]
[VSPACE = pixels]
[HSPACE = pixels]
[ARCHIVE = URL to archive]
[MAYSCRIPT]
>
[<PARAM NAME = appletAttribute1 VALUE = value>]
[<PARAM NAME = appletAttribute2 VALUE = value>]
. . .
[alternateHTML]
</APPLET>

CODEBASE=URL
This optional attribute specifies the base URL of the applet -- the directory that contains the applet's code. If this attribute is not specified, then the document's URL is used.

CODE=appletFile
This required attribute gives the name of the file that contains the applet's compiled Applet subclass. This file is relative to the base URL of the applet. It cannot be absolute.

ALT=alternateText
This optional attribute specifies any text that should be displayed if the browser understands the APPLET element but can't run applets written in the Java Programming Language.

NAME=appletInstanceName
This optional attribute specifies a name for the applet instance, which makes it possible for applets on the same page to find (and communicate with) each other.

WIDTH=pixels HEIGHT=pixels
These required attributes give the initial width and height (in pixels) of the applet display area, not counting any windows or dialogs that the applet brings up.

ALIGN=alignment
This required attribute specifies the alignment of the applet. The possible values of this attribute are the same as those for the <IMG> element: left, right, top, texttop, middle, absmiddle, baseline, bottom, absbottom.

VSPACE=pixels HSPACE=pixels
These option attributes specify the number of pixels above and below the applet (VSPACE) and on each side of the applet (HSPACE). They're treated the same way as the <IMG> element's VSPACE and HSPACE attributes.

ARCHIVE=compressed file
This optional attribute specifies the location (relative to the CODEBASE of the main class file) of a compressed file (consisting of all the necessary class files and support images/sounds etc.) that may be downloaded to the users Hard Disk, to save download time should they return to the page at a later date. Any files not contained in this archive that are needed will be searched for by the browser in the normal way. NOTE : The ARCHIVE attribute is Netscape specific.

MAYSCRIPT
This attribute is a flag that when used, specifies that the applet is scriptable by JavaScript functions.

<PARAM NAME=appletAttribute1 VALUE=value>
This element is the only way to specify an applet-specific attribute. Applets access their attributes with the getParameter() method.