HTML and CSS Reference
In-Depth Information
Adding a Java Applet to a Web Page
The W3C recommends using the <object> tag to configure a Java applet on a Web
page and has deprecated the <applet> tag. However, in practice, the <applet> tag will
more reliably display a Java applet on a Web page in commonly used browsers. This
example will use the <applet> tag. The <applet> tag specifies the beginning of an
applet area in the body of a Web page. Its closing tag, </applet> , specifies the ending
of an applet area in the body of a Web page. The <applet> tag has a number of attrib-
utes described in Table 11.5.
Table 11.5 Attributes of the <applet> tag
Name of the applet file; this has a .class file extension
If the applet is not in the same folder as the Web page, the codebase indicates the folder that contains
the applet
Specifies the height of the applet area in pixels
Specifies the width of the applet area in pixels
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 <param /> tags. The <param /> tag is a self-contained tag with
two attributes: name and 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.
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.
Search WWH ::

Custom Search