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
Writing the Code to Support Parameters

> Applets use the `Applet getParameter` method to get user-specified values for applet parameters. The `getParameter` method is defined as follows:

> >     public String getParameter(String name)

> Your applet might need to convert the string that `getParameter` returns into another form, such as an integer. The `java.lang` package provides classes such as Integer that you can use to help with converting strings to primitive types. Here's an example of converting a parameter's value into an integer:

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

> Note that if the user doesn't specify a value for the `WINDOWWIDTH` parameter, the above code uses a default value of 0, which the applet interprets as "use the window's natural size." It's important that you supply default values wherever possible.

> Besides using the `getParameter` method to get values of applet-specific parameters, you can also use `getParameter` to get the values of attributes of the applet's `<APPLET>` tag. See Using the applet Tag for a list of `<APPLET>` tag attributes.

Previous page: Deciding Which Parameters to Support
Next page: Giving Information about Parameters