Web Development and Design Foundations with XHTML, 5th Edition

(Steven Felgate) #1

(^446) Chapter 11 Web Multimedia and Interactivity
Adding a Java Applet to a Web Page
The W3C recommends using the tag to configure a Java applet on a Web
page and has deprecated the tag. However, in practice, the tag will
more reliably display a Java applet on a Web page in commonly used browsers. This
example will use the tag. The tag specifies the beginning of an
applet area in the body of a Web page. Its closing tag,
, specifies the ending
of an applet area in the body of a Web page. The tag has a number of attrib-
utes described in Table 11.5.
Table 11.5Attributes of the tag
Attribute Value
code Name of the applet file; this has a .class file extension
codebase If the applet is not in the same folder as the Web page, the codebase indicates the folder that contains
the applet
height Specifies the height of the applet area in pixels
width Specifies the width of the applet area in pixels
alt A text description of the applet
In addition, most applets need special values, or parameters, to configure their process-
ing. An applet that shows images and handles navigation would need parameters to
accept the file names of the images and the URLs for the hyperlinks. The programmer
who creates an applet determines the parameter values and names required by a specific
Java applet. Therefore, expect each applet to require different parameters. Parameters
are configured with tags. The tag is a self-contained tag with
two attributes: nameand value. The parameter name is provided in the applet docu-
mentation. The parameter value will be different depending on the function of the
applet. One parameter might be used to set a background color; another parameter
could be used to contain a person’s name. A description of the type of value expected
should be contained in the applet documentation.
HANDS-ON PRACTICE 11.5
In this Hands-On Practice you will launch Notepad and create a Web page that con-
tains a Java applet. This example will use the Fader26 applet (provided by Johannes
Schellen). This applet displays text messages one at a time. The list of text messages is
obtained from a text file (.txt file extension) that you will create. An example of this
applet at work can be found in the student files at Chapter11/java1.html.
Let’s get started. Create a folder called testapplet on your disk. Copy the applet file
(fader26.class) from the student files at Chapter11/fader26.class and place it in the
testapplet folder. Do not change the name of the applet.
Whether you obtain an applet from a free Web site or from a coworker, each applet
should have some accompanying documentation that indicates what parameter it
expects. Documentation for the Fader26 applet appears in Table 11.6.