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

Trail: Writing Applets
Lesson: Taking Advantage of the Applet API

Giving Information about Parameters

Now that you've provided all those nice parameters to the user, you need to help the user set the parameter values correctly. Of course, your applet's documentation should describe each parameter and give the user examples and hints of setting them. Your job doesn't stop there, though. You should also implement the getParameterInfo method so that it returns information about your applet's parameters. Browsers can use this information to help the user set your applet's parameter values.

Below is an example of implementing the getParameterInfo method. This example is from the Animator (in a .java source file) applet, a wonderfully flexible applet that provides 13 parameters for users to customize their animation.

public String[][] getParameterInfo() {
    String[][] info = {
      // Parameter Name     Kind of Value   Description
        {"imagesource",     "URL",          "a directory"},
        {"startup",         "URL",          "displayed at startup"},
        {"background",      "URL",          "displayed as background"},
        {"startimage",      "int",          "start index"},
        {"endimage",        "int",          "end index"},
        {"namepattern",     "URL",          "used to generate indexed names"},
        {"pause",           "int",          "milliseconds"},
        {"pauses",          "ints",         "milliseconds"},
        {"repeat",          "boolean",      "repeat or not"},
        {"positions",       "coordinates",  "path"},
        {"soundsource",     "URL",          "audio directory"},
        {"soundtrack",      "URL",          "background music"},
        {"sounds",          "URLs",         "audio samples"},
    };
    return info;
}    
As you can see, the getParameterInfo method must return an array of three-String arrays. In each three-String array, the first string is the parameter name. The second string gives the user a hint about what general kind of value the applet needs for the parameter. The third string describes the meaning of the parameter.

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

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