Basic HTML
Java Applets
Even if you don't know how to program in Java,
you can still employ Java applets that someone
else has already written.
Java Example: TickerTape
Applet
Many applets let users perform a degree of customization
using only HTML commands. A nice example is the following
ticker tape display developed by an Egyptian company named
ITS.
We've added this to our page using the following HTML:
<applet code=NavigatorTicker11.class width=300
height=28>
<param name=count value=2>
<param name=msg0 value=
"Welcome to Fred Fargle's Homepage.. Just Click
to Connect *** \\No Link">
<param name=msg1 value=
"Visit: Tech Corps -- technology volunteers
for K-12 schools \\http://www.techcorps.org/">
<param name=speed value=8>
<param name=bgco value=50,0,200>
<param name=txtco value=250,250,0>
<param name=linkco value=180,25,21>
</applet>
|
The actual Java program is in file NavigatorTicker11.class;
this is a compiled binary file, in a platform independent
format know as byte-code (compiled Java
applets will generally have the extension .class
in their filenames; they are often termed class files).
The CODE and
CODEBASE Fields
Note that the Java code is not part of the HTML
file but is only referenced by the HTML. An HTML applet
tag is used to insert the applet on the page. The tag
tells the browser the name (and location) of the file containing
the Java code that is to be inserted on the page.
The name is supplied through the statement
code=NavigatorTicker11.class.
In this example, it is implied that this class file is
located in the same directory (folder) as this HTML document.
You can also place the Java code in a directory
other than the one containing the HTML file, but then you
must specify the location of this new directory (relative
to the HTML file) by providing a value for codebase.
For example, if we were to add codebase=/Java/NavTicker
inside the applet tag,
<applet codebase=/Java/NavTicker
code=NavigatorTicker11.class width=300
height=28>
|
we would indicate that the NavigatorTicker11.class
file was in a subdirectory named NavTicker of a
directory named Java that was itself a subdirectory
of the directory containing the HTML file for this page.
This could be useful, for example, if we have used the same
applet in more than one document. If you are going to use
applets that are not in the same directory the HTML file
that calls them, you may wish to review the section on Relative
Addressing.
Specification of Applet
Parameters
The other items in the above applet tag are specifications
of parameters that allow the user to customize the behavior
of the applet (these are the lines beginning with "param").
The meanings of the parameters for the TickerTape applet
are:
- count -- total
number of messages (3 in the above example)
- msg0, msg1, ...
-- individual messages; note that the count starts with
0, not 1; each consists of the message text, followed
by two backslashes, followed by a URL (linking the message
to the URL)
- txtco -- color
of message text, coded as a (Red, Green, Blue) RGB triplet
with the components separated by commas, and each component
a number in the range 0-255 indicating the amount of red,
green, and blue, respectively (for example, the triple
255, 255, 255 is white, 0, 0, 0 is black, and 0, 255,
0 is pure green).
- bgco -- background
color (denoted in the same format as )
- linkco -- active
link color (same format as txtco)
- speed -- specifies
the scrolling speed
Note that each displayed message can contain a hypertext
link. The URL for the link is displayed at the bottom of
the browser window when the cursor is placed over that scrolling
message. You can activate a link by clicking on it as it
scrolls by. If a message does not contain a link you should
still include two backslashes after the message text (followed
by optional text that will be displayed at the bottom of
the browser window when the cursor is placed over that message).
Add the TickerTape Applet
to Your Page
You can add this ticker tape banner to your pages and
have it display whatever message(s) you desire. You only
need to get the file
NavigatorTicker11.class,
add the above section of HTML code to the desired spot on
your page, and modify the parameters to show the messages
you want in the colors and speed you like (remember to place
the Java class file in the same directory as your
homepage file unless you add a codebase specification
to indicate which directory it is in). The applet is free
for you to use. The author only asks that you give credit
to its developer.
Customizing the Applet
Experiment with modifying the example:
- Change Fred's name to your
own, to make the banner a greeting to your homepage.
- Add a fourth message. (Don't
forget to update the value of the count parameter!)
- Change the background color
to bright red (255,0,0).
- Change the text color to
cyan (0,255,255).
- Experiment with changing
the scrolling speed. What happens if you use values of
the speed parameter greater than 8? Less than 8?
- Now customize the banner
to display the messages that you would like for it to
display and add it to your homepage.
Note: In some cases the applet may not be reloaded
with the new parameters in effect if you simply reload the
Web page. You may have to exit your browser and restart
it in order to see the changes. Java is a rather
new language on the Web and there still are some bugs in
its implementation for many browsers.
Some More Examples
If you would like to add more applets to your Web pages,
check out some additional examples at
Be sure to download the class file (or files) and a sample
applet tag showing what parameters can be set for any applets
that you want to add to your pages. In all cases, give credit
where credit is due if you are using someone else's applet.
|