Experiment J4.6, Step 4. It is likely that you failed in your attempt. Java only lets you switch on selected primitive types, and not on strings and other objects.
Experiment J4.7, Step 5.
Hopefully, you've observed that the capitalization used within the
param tag does not affect the passing of the parameter
to the applet. In fact, the Java specification says that parameters
Experiment J4.7, Step 6.
Hopefully, you've observed that the capitalization of the string used
getParameter tag does not affect the passing of the
parameter to the applet. In both cases (
param tag and
getParameter), the Java specification says that
parameters are case-insensitive.
Experiment J4.7, Step 7.
It may seem confusing that the parameter is called
in the HTML file, but is stored in the variable
within the applet. However, Java does not require you to use the
same name for the variable that stores a parameter that you've used
for naming the parameter. We'll take advantage of this ability to
choose a different internal name in the next experiment.
Experiment J4.7, Step 8.
As you may have surmised, there is no longer a parameter tag for
greeting parameter that the applet expects. Hence,
drawString method is unhappy with the
string and gives an error.
Experiment J4.8, Step 1. Since the applet does not yet read these new parameters, they have no effect.
Experiment J4.8, Step 4.
While the name of the parameter is case-insensitive, the value
of the parameter is case-sensitive. Java treats
"WHITE" as different strings.
Hence, none of the strings match
the applet never changes
Color.red (which it was set to at the start of the
Experiment J4.8, Step 10.
As suggested earlier, the
try/catch permits us to specify
a default value. More imporantly, it stops the program from reporting
an error when we use values that Java does not know how to convert.
Copyright (c) 1998 Samuel A. Rebelsky. All rights reserved.
Source text last modified Thu Aug 5 12:02:51 1999.
This page generated on Thu Aug 5 13:39:28 1999 by SiteWeaver.
Contact our webmaster at email@example.com