img
fontSize = 0;
} catch(NumberFormatException e) {
fontSize = -1;
}
param = getParameter("leading");
try {
if(param != null) // if not found
leading = Float.valueOf(param).floatValue();
else
leading = 0;
} catch(NumberFormatException e) {
leading = -1;
}
param = getParameter("accountEnabled");
if(param != null)
active = Boolean.valueOf(param).booleanValue();
}
// Display parameters.
public void paint(Graphics g) {
g.drawString("Font name: " + fontName, 0, 10);
g.drawString("Font size: " + fontSize, 0, 26);
g.drawString("Leading: " + leading, 0, 42);
g.drawString("Account Active: " + active, 0, 58);
}
}
Sample output from this program is shown here:
As the program shows, you should test the return values from getParameter( ). If a
parameter isn't available, getParameter( ) will return null. Also, conversions to numeric
types must be attempted in a try statement that catches NumberFormatException. Uncaught
exceptions should never occur within an applet.
Improving the Banner Applet
It is possible to use a parameter to enhance the banner applet shown earlier. In the previous
version, the message being scrolled was hard-coded into the applet. However, passing the
message as a parameter allows the banner applet to display a different message each time it
is executed. This improved version is shown here. Notice that the APPLET tag at the top of
the file now specifies a parameter called message that is linked to a quoted string.
// A parameterized banner
import java.awt.*;
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home