Netscape and Explorer support embedded applets which are programs,
written in Java, that can be embeded within a HTML document and
executed. This embedding is done via the <APPLET>
and </APPLET> tags.
The <APPLET> tag can have the following attributes:
CODE - This required attribute tells the browser
which Java executable file (or class) to execute.
CODEBASE - Informs the browser of the location to find
all of the files pertaining to the applet if they are not in the same
directory as the HTML document which called the applet. This can be
specified using relative or absolute URLs.
WIDTH and HEIGHT are required,
are in pixels, and tell the browser how much space on the web page the applet
is to take.
<PARAM> elements. Within each
<PARAM> element there should be:
NAME is the name of the parameter being passed.
VALUE is the value to pass for the associated NAME.
<PARAM> tag does not require a closing
</PARAM> tag.To display text in place of the applet for browsers which do not support the applet tags, just place the text you wish to display within the applet tag.
Here are some examples:
This HTML code loads the Java Applet entitledfader.class,
and allots a space on the web page 300 pixels wide and 100 pixels high.
Two parameters are required by the applet. The first parameter, called
text is passed the value This is the text to fade!
while the second parameter is entitled speed and the value
passed to it is 4. In case the browser viewing this web
page does not support the applet tags, the text If your browser
supported applets, you would see one here. is displayed instead.
<APPLET CODE="fader.class" WIDTH=300 HEIGHT=100> <PARAM NAME="text" VALUE="This is the text to fade!"> <PARAM NAME="speed" VALUE="4"> If your browser supported applets, you would see one here. </APPLET>
fireworks.class,
and allots a space on the web page 50 pixels wide and 30 pixels high.
Any other java code required by this applet can be found in the
java directory which lies in the current directory that
this web page was loaded from. Three parameters are required by the
applet. Their names and associated values are passed using the
<PARAM> tag.
<APPLET CODE="fireworks.class" CODEBASE="java" WIDTH=50 HEIGHT=30> <PARAM NAME="color" VALUE="random"> <PARAM NAME="number" VALUE="12"> <PARAM NAME="breaks" VALUE="huge"> </APPLET>
scroll.class,
and allots a space on the web page 500 pixels wide and 60 pixels high.
Any other java code required by this applet can be found at the web site
http://lozinski.virginia.com in the classes
directory. The parameters required by the
applet, their names, and associated values are passed using the
<PARAM> tag.
<APPLET CODE="scroll.class" CODEBASE="http://lozinski.virginia.com/classes" WIDTH=500 HEIGHT=60> <PARAM NAME="direction" VALUE="left"> <PARAM NAME="text" VALUE="Scrolls to the left."> <PARAM NAME="color" VALUE="blue"> <PARAM NAME="fade" VALUE="true" <PARAM NAME="direction" VALUE="up"> <PARAM NAME="text" VALUE="Scrolls up."> <PARAM NAME="color" VALUE="red"> <PARAM NAME="fade" VALUE="false"> </APPLET>
The number and types of parameters as well as the attributes are going to be dependent on each applet being used. The examples presented here are just that -- examples. Please consult any documentation that should come with your applet for details on how to set it up in your web page.
The Java programming language is beyond the scope of this course. If you are interested in teaching yourself Java and learning how to program applets, I recommend the book Java by Example, written by Clayton Walnum and published by QUE.