The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Deployment
Lesson: Applets

Deciding Which Parameters to Support

This page guides you through the four questions you should ask as you implement parameters:

It ends with a discussion of the parameters defined in a sample <APPLET> tag.

What Should the Applet Let the User Configure?

The parameters your applet should support depend on what your applet does and on how flexible you want it to be. Applets that display images might have parameters to specify the image locations. Similarly, applets that play sounds might have parameters to specify the sounds.

Besides parameters that specify resource locations (such as image and sound files), applets sometimes provide parameters for specifying details of the applet's appearance or operation. For example, an animation applet might let the user specify the number of images shown per second. Or an applet might let the user change the strings the applet displays. Anything is possible.

What Should the Parameters Be Named?

Once you decide what parameters your applet will support, you need to figure out their names. Here are some typical parameter names:
SOURCE or SRC
For a data file such as an image file.
XXXSOURCE (for example, IMAGESOURCE)
Used in applets that let the user specify more than one type of data file.
XXXS
For a parameter that takes a list of XXXs (where XXX might be IMAGE, again).
NAME
Used only for an applet's name. Applet names are used for interapplet communication, as described in Sending Messages to Other Applets (in the Deployment trail).

Clarity of names is more important than keeping the name length short. Do not use names of <APPLET> tag attributes, which are documented in Using the applet Tag (in the Deployment trail).


Note:  Although this tutorial usually refers to parameter names using ALL UPPERCASE, parameter names are case-insensitive. For example, IMAGESOURCE and imageSource both refer to the same parameter. Parameter values, on the other hand, are case-sensitive unless you take steps to interpret them otherwise, such as by using the String toLowerCase method before interpreting the parameter's value.

What Kind of Value Should Each Parameter Take?

Parameter values are all strings. Whether or not the user puts quotation marks around a parameter value, that value is passed to your applet as a string. However, your applet can interpret the string in many ways.

Applets typically interpret a parameter value as one of the following types:

What Should the Default Value of Each Parameter Be?

Applets should attempt to provide useful default values for each parameter, so that the applet will execute even if the user doesn't specify a parameter or specifies it incorrectly. For example, an animation applet should provide a reasonable setting for the number of images it displays per second. This way, if the user doesn't specify the relevant parameter, the applet will still work well.

An Example: A Sample <APPLET> Tag

Here's what a typical <APPLET> tag looks like.
<APPLET CODE=SampleApplet.class CODEBASE=example
     WIDTH=350 HEIGHT=60>
<PARAM NAME=windowClass VALUE=BorderWindow>
<PARAM NAME=windowTitle VALUE="BorderLayout">
<PARAM NAME=buttonText
       VALUE="Click here to see a BorderLayout in action">
</APPLET>

When the user doesn't specify a value for a parameter, the applet uses a reasonable default value. For example, if the user doesn't specify the window's title, the applet uses the window's type as the title.

The next page shows you how to get parameter values from the user.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.