To display an applet on a Web page, you need to add appropriate commands to the associated HTML file. Below, we describe these HTML commands and introduce some of the many "plug-n-play" applets available on the Web. Plug-n-play means that the applets are ready to be plugged into your Web pages with a minimum of effort. No programming required!
This is an introduction to using applets. For more details on the subject, see the text, Hooked on Java" available in the User Services Reference Library, 014 Smith Hall.
<HTML> <HEAD> <TITLE>The Bare Minimum</TITLE> </HEAD> <BODY> . . <APPLET code=appletname.class width=integervalue length=integervalue > </APPLET> . </BODY> <HTML>"appletname.class" is the name of the class containing the applet. The width and length attributes are in pixel units and these attributes together with "code" are the bare minimum. Note that the location of the applet file is the same as the HTML file (You can reference an applet in another location by using the codebase optional attribute). These three attributes, the width, length, and code are required applet attributes. Other attributes are optional. An example of an applet using only the minimum required attributes is the under construction applet.
There are several optional applet attributes including those having to do with the alignment of the applet with respect to surrounding text. For more information on the applet tag, see Sun's Applet TagWeb page.
As an example, assume that an applet is contained in the
class file, "test.class", and
has parameters "p1" and "p2" that take numerical values, the
corresponding HTML code would look like this:
Example:
A series of images (gif files) were created using the Maple Symbolic Computation
program. This sequence of graphs depicted a 3-d sine-cosine wave (with sound).
Applet Parameters
An applet can also have parameters that allow you to customize the applet. For
example, the banner applet used at the top of this Web page uses parameters that specify the background and foreground colors of the banner.
Applet parameters
are specified by using the <param> tag.
<HTML>
<HEAD>
<TITLE>Using Parameters</TITLE>
</HEAD>
<BODY>
.
.
<APPLET code=test.class width=100 length=300 >
<PARAM name=p1 value=100>
<PARAM name=p2 value=200>
</APPLET>
.
</BODY>
<HTML>
Another example of an applet that uses parameters
is the "Animator" applet. The Animator applet will animate a
sequence of images and allow you to specify several parameters including
the starting and ending image, the duration between and during each image, and
a background image file. You can get complete details about the Animator from the Sun's Animator
Web page.
The Animator applet illustrates an applet that gets it's input
data from an external user supplied file.
The scrolling applet at the top of this page reads a data file for the contents and type of the scrolling text. The applet is also interactive because if you click on the banner, "Making Banners is Easy with Java", you will link to the Funscroll homepage where you can get details and examples of using this applet.
Here are some other interactive applets you can try: