Java Reference
In-Depth Information
label = s;
textField = t;
greeting = s.getText();
}
public void actionPerformed(ActionEvent a)
{
String name = textField.getText();
if(name != null && !(name.equals(“”)))
{
label.setText(greeting + “, “ + name);
}
}
}
The buttonLabel parameter of HelloWorldApplet2 becomes the label on the
button. The greeting parameter becomes the greeting displayed in the applet.
Figure 14.8 shows HelloWorldApplet2 displayed in a Web browser using the
paramdemo.html page, where the buttonLabel parameter is “Click here” and
the greeting parameter is “Merry Christmas.”
In the HelloWorldApplet2 class, if the buttonLabel parameter is not
defined, the button label will be Go. Similarly, the greeting defaults to
Hello if no greeting parameter is provided. When writing an applet, you
should always have meaningful default values for parameters to allow for
situations where the parameters are not provided by the HTML author.
Figure 14.8
Greeting and button label are determined by parameters.