2. Creating an Interface

2.1.1. An Applet extends the graphic class Panel

It can contain other Components, just as any Panel can. As Panels (and thus Components), Applets participate in the AWT drawing and event hierarchy.

Figure 12.2. Quote Applet

Quote Applet

Figure 12.3. Window Applet

Window Applet

Applet methods:

  • play(URL), play(URL, String)

    Play the AudioClip corresponding to the specified URL.

  • getAudioClip(URL), getAudioClip(URL, String)

    Return an object that implements the AudioClip interface.

The AudioClip interface:

  • loop()

    Starts playing the clip repeatedly.

  • play()

    Plays the clip once.

  • stop()

    Stops the clip. Works with both looping and one-time sounds.

Audio in Portuguese

2.2.1. Code to support parameters

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

2.2.2. Giving information about parameters

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

Audio in Portuguese

Command to Read System Properties:

String s = System.getProperty("os.name");

System Properties that Applets Can Read:

Table 12.1. Available System Properties

KeyMeaning
"file.separator"File separator (e.g., "/")
"java.class.version"Java class version number
"java.vendor"Java vendor-specific string
"java.vendor.url"Java vendor URL
"java.version"Java version number
"line.separator"Line separator
"os.arch"Operating system architecture
"os.name"Operating system name
"path.separator"Path separator (e.g., ":")

Forbidden System Properties:

Table 12.2. Forbidden System Properties

KeyMeaning
"java.class.path"Java classpath
"java.home"Java installation directory
"user.dir"User's current working directory
"user.home"User home directory
"user.name"User account name

Print in the browser status line:

showStatus("MyApplet: Loading image file " + file);

Audio in Portuguese