Applets with parameters

12 February 2008

Applets may accept parameters. This post briefly shows how to do that.

Applet in included in HTML using APPLET tag. You have to specify the parameters in APPLET tag in the following form:

<APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
<PARAM NAME=parameter1Name VALUE=aValue>
<PARAM NAME=parameter2Name VALUE=anotherValue>
</APPLET>

Let me show you with an example:

<APPLET CODE="Animator.class" WIDTH=460 HEIGHT=160
 ALT="If you could run this applet, you'd see some animation">
<PARAM NAME="imageSource" VALUE="images/Beans">
<PARAM NAME="backgroundColor" VALUE="0xc0c0c0">
<PARAM NAME="endImage" VALUE=10>
<PARAM NAME="soundSource" VALUE="audio">
<PARAM NAME="soundtrack" VALUE="spacemusic.au">
<PARAM NAME="sounds"
       VALUE="1.au|2.au|3.au|4.au|5.au|6.au|7.au|8au|9.au|0.au">
<PARAM NAME="pause" VALUE=200>
Your browser is completely ignoring the APPLET tag!
</APPLET>

Now, applet will be send parameters and in the applet, we have to get them and have to act accordingly. Applet code to get the parameters is as follows:

int requestedWidth = 0;
. . .
String windowWidthString = getParameter("WINDOWWIDTH");
if (windowWidthString != null) {
    try {
        requestedWidth = Integer.parseInt(windowWidthString);
    } catch (NumberFormatException e) {
        //Use default width.
    }
}

Play around and explore.

del.icio.us:Applets with parameters  digg:Applets with parameters  spurl:Applets with parameters  wists:Applets with parameters  simpy:Applets with parameters  newsvine:Applets with parameters  blinklist:Applets with parameters  furl:Applets with parameters  reddit:Applets with parameters  fark:Applets with parameters  blogmarks:Applets with parameters  Y!:Applets with parameters  smarking:Applets with parameters  magnolia:Applets with parameters  segnalo:Applets with parameters  gifttagging:Applets with parameters

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Applets with parameters

Leave a Reply