Download the JDK
Search the Tutorials
Hide the TOC
Trail: Deployment
Lesson: Applets
Section: Taking Advantage of the Applet API
Subsection: Defining and Using Applet Parameters
Applets
Getting Started with Applets
Importing Classes and Packages for Applets
Defining an Applet Subclass
The Life Cycle of an Applet
Methods for Milestones
Methods for Drawing and Event Handling
Methods for Adding UI Components
What Applets Can and Can't Do
Taking Advantage of the Applet API
Finding and Loading Data Files
Displaying Short Status Strings
Displaying Documents in the Browser
Sending Messages to Other Applets
Playing Sounds
Defining and Using Applet Parameters
Deciding Which Parameters to Support
Writing the Code to Support Parameters
Giving Information about Parameters
Using the APPLET Tag
Practical Considerations When Writing Applets
Security Restrictions
Creating a User Interface
Creating a GUI
Displaying Diagnostics to the Standard Output and Error Streams
Getting System Properties
Threads in Applets
Threads in Applets: Examples
Working with a Server-Side Application
A Simple Network Client Applet
Using a Server to Work Around Security Restrictions
Finishing an Applet
Before You Ship that Applet
The Perfectly Finished Applet
Deploying Applets
General Deployment Considerations
Using the applet Tag
Using the object Tag
Using the embed Tag
Deploying Applets in a Mixed-Browser Environment
Solving Common Applet Problems
Questions and Exercises
Home Page > Deployment > Applets
Deciding Which Parameters to Support

> 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.

### 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.

> 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` 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:

> - 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

### 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: Defining and Using Applet Parameters
Next page: Writing the Code to Support Parameters