Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
This page guides you through the four questions you should ask as you implement parameters:
- What should the applet let the user configure?
- What should the parameters be named?
- What kind of value should each parameter take?
- What should the default value of each parameter be?
It ends with a discussion of the parameters defined in a sample
<APPLET>
tag.
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.
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.
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.
Note: Although this tutorial usually refers to parameter names using ALL UPPERCASE, parameter names are case-insensitive. For example,IMAGESOURCE
andimageSource
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 theString toLowerCase
method before interpreting the parameter's value.
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:
- A URL
- An integer
- A floating-point number
- A boolean value -- typically "true"/"false" or "yes"/"no"
- A string -- for example, the string to use as a window title
- A list of any of the above
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.
<APPLET>
TagHere'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.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.