Chapter 3: Using Java on Your Pages

index | previous | next  
 
 
 
Listing 3.5 . This example shows how to refer to an applet with multiple parameters.

Listing
<HTML>
<HEAD>
  <TITLE>Tiny Scroller</TITLE>
</HEAD>
<BODY BGCOLOR=WHITE>
  <APPLET CODEBASE="classes" CODE=
    -> "tinyScroller.class" WIDTH=200 HEIGHT=150>
  <PARAM NAME="LINE1" VALUE="In today's top
   
-> story:">
  <PARAM NAME="LINE2" VALUE=" Java: Visual
   
-> QuickStart Guide
  <PARAM NAME="LINE3" VALUE=" breaks all
    -> previous sales">
  <PARAM NAME="LINE4" VALUE=" records, as rumor
    -> spreads">
  <PARAM NAME="LINE5" VALUE=" that book
    -> contains">
  <PARAM NAME="LINE6" VALUE=" hard-hitting
    -> information,">
  <PARAM NAME="LINE7" VALUE=" sparkling prose,">
  <PARAM NAME="LINE8" VALUE=" live nude girls,">
  <PARAM NAME="LINE9" VALUE=" and free beer">
  <PARAM NAME="BGRED" VALUE="255">
  <PARAM NAME="BGGREEN" VALUE="255">
  <PARAM NAME="BGBLUE" VALUE="255">
  <PARAM NAME="FGRED" VALUE="0">
  <PARAM NAME="FGGREEN" VALUE="0">
  <PARAM NAME="FGBLUE" VALUE="0">
  <PARAM NAME="DELAY" VALUE="5">
  <PARAM NAME="MAXLINE" VALUE="9">
  <H1>You should use a Java-enabled
    -> browser!</H1>
 </APPLET>
</BODY>
</HTML>

 
 

Passing parameters to an applet

In order to use a canned applet, you need a way to pass parameters from HTML to Java.In other words, someone who knows only HTML should be able to get the applet to display something different by making changes to the page in HTML. This is accomplished by means of the PARAM tag used within the APPLET tag as shown in Listing 3.5.

A well-documented applet will include a list of all the possible parameters, showing all the possible values including default values. The documentation for the tinyScroller applet (as downloaded in the previous section) is shown in the sidebar on the next page.

If a canned applet doesn't accept parameters you can still use it on your page, but it means that what you're displaying isn't personalized in any way - anyone else with the same applet will have identical results. Here, we pass parameters to the tinyScroller applet to display a unique page.