Java Reference
In-Depth Information
code
= classfilename.class
width
= applet_viewing_width_in_pixels
height
= applet_viewing_height_in_pixels
[
archive
= archivefile]
[
vspace
= vertical_margin]
[
hspace
= horizontal_margin]
[
align
= applet_alignment]
[
alt
= alternative_text]
>
<
param name
= param_name1
value
= param_value1>
<
param name
= param_name2
value
= param_value2>
...
<
param name
= param_namei
value
= param_valuei>
</applet>
<param>
tag
The
code
,
width
, and
height
attributes are required; all the others are optional. The
<param>
tag will be introduced in Section 18.7, Passing Strings to Applets. The other attrib-
utes are explained below.
■
codebase
specifies the base from which your classes are loaded. If this attribute is
not used, the Web browser loads the applet from the directory in which the HTML
page is located. If your applet is located in a different directory from the HTML
page, you must specify the
applet_url
for the browser to load the applet. This
attribute enables you to load the class from anywhere on the Internet. The classes
used by the applet are dynamically loaded when needed.
■
archive
instructs the browser to load an archive file that contains all the class files
needed to run the applet. Archiving allows the Web browser to load all the classes
from a single compressed file at one time, thus reducing loading time and improving
performance. To create archives, see Supplement III.Q, Packaging and Deploying
Java Projects.
■
vspace
and
hspace
specify the size, in pixels, of the blank margin to pad around
the applet vertically and horizontally.
■
align
specifies how the applet will be aligned in the browser. One of nine values is
used:
left
,
right
,
top
,
texttop
,
middle
,
absmiddle
,
baseline
,
bottom
, or
absbottom
.
■
alt
specifies the text to be displayed in case the browser cannot run Java.
codebase
attribute
archive
attribute
18.3.1 Viewing Applets from a Web Browser
To display an applet from a Web browser, open the applet's HTML file (e.g.,
DisplayLabel.html
). Its output is shown in Figure 18.2a.
To make your applet accessible on the Web, you need to store the
DisplayLabel.class
and
DisplayLabel.html
files on a Web server, as shown in Figure 18.3. You can view the applet
(a)
(b)
F
IGURE
18.2
The DisplayLabel program is loaded from a local host in (a) and from a Web server in (b).