start page | rating of books | rating of authors | reviews | copyrights

Java in a Nutshell

Previous Chapter 15 Next
 

15. Java-Related HTML Tags

Contents:
The <APPLET> Tag
The <PARAM> Tag
An Example HTML File

This chapter explains what you need to know about HTML to work with Java applets.

15.1 The <APPLET> Tag

A Java applet is included in a Web page with the <APPLET> tag, which has the following syntax. Items in brackets ([]) are optional.

<APPLET
    CODE = applet-filename
    WIDTH = pixel-width
    HEIGHT = pixel-height
    [OBJECT = serialized-applet-filename]
    [ARCHIVE = jar-file-list]
    [CODEBASE = applet-url]
    [ALT = alternate-text]
    [NAME = applet-name]
    [ALIGN = alignment]
    [VSPACE = vertical-pixel-space]
    [HSPACE = horizontal-pixel-space]
>
[<PARAM NAME = parameter VALUE = value>]
[<PARAM NAME = parameter VALUE = value>]
    ...
[alternate-text]
</APPLET>

APPLET

The <APPLET> tag specifies an applet to be run within a Web document. A Web browser that does not support Java and does not understand the <APPLET> tag ignores this tag and any related <PARAM> tags, and simply displays any alternate-text that appears between <APPLET> and </APPLET>. A browser that does support Java runs the specified applet, and does not display the alternate-text.

CODE

This required attribute specifies the file that contains the compiled Java code for the applet. It must be relative to the CODEBASE if that attribute is specified, or relative to the current document's URL. It must not be an absolute URL. In Java 1.1, this attribute can be replaced with an OBJECT attribute.

WIDTH

This attribute specifies the initial width, in pixels, that the applet needs in the browser's window. It is required.

HEIGHT

This attribute specifies the initial height, in pixels, that the applet needs in the browser's window. It is required.

OBJECT

As of Java 1.1, this attribute specifies the name of a file that contains a serialized applet that is to be created by deserialization. An applet specified in this way does not have its init() method invoked, but does have its start() method invoked. Thus, before an applet is saved through serialization, it should be initialized, but should not be started, or, if started, it should be stopped. An applet must have either the CODE or OBJECT attribute specified, but not both.

ARCHIVE

As of Java 1.1, this attribute specifies a comma-separate list of JAR (Java Archive) files that are "preloaded" by the Web browser or applet viewer. These archive files may contain Java class files, images, sounds, properties, or any other resources required by the applet. The Web browser or applet viewer searches for required files in the archives before attempting to load them over the network.

CODEBASE

This optional attribute specifies the base URL (absolute or relative) of the applet to be displayed. This should be a directory, not the applet file itself. If this attribute is unspecified, then the URL of the current document is used.

ALT

This optional attribute specifies text that should be displayed by browsers that understand the <APPLET> tag but do not support Java.

NAME

This optional attribute gives a name to the applet instance. Applets that are running at the same time can look each other up by name and communicate with each other.

ALIGN

This optional attribute specifies the applet's alignment on the page. It behaves just like the ALIGN attribute of the <IMG> tag. Its allowed values are: left, right, top, texttop, middle, absmiddle, baseline, bottom, and absbottom.

VSPACE

This optional attribute specifies the margin, in pixels, that the browser should put above and below the applet. It behaves just like the VSPACE attribute of the <IMG> tag.

HSPACE

This optional attribute specifies the margin, in pixels, that the browser should put on either side of the applet. It behaves just like the HSPACE attribute of the <IMG> tag.


Previous Home Next
Working with System Properties Book Index The <PARAM> Tag

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java