Java Reference
In-Depth Information
In addition to these attributes, an <applet> tag can also contain any number
of parameters, which are defined using the <param> tag. The <param> tag is
nested within the <applet> tag, and has two attributes: name and value. The
syntax for using <param> is:
<applet>
<param name=”parameter name” value=”value”>
<param name=”parameter name” value=”value”>
...
</applet>
An applet can obtain the parameters using the following Applet method:
public String getParameter(String name). Returns the value of the given
parameter. The return value is null if the parameter is not defined.
Parameters allow the writer of an applet to customize the applet based on
input from the writer of the HTML page. Proper use of parameters can make
your applets flexible and capable of being used in many different situations.
For example, the following HTML document, paramdemo.html, displays an
applet named HelloWorldApplet2, which is similar to the HelloWorldApplet
discussed earlier, except that it uses two parameters to determine the label on
the button and the greeting.
<html>
<body>
<h2>Enter your name and click the button.</h2>
<applet code=”HelloWorldApplet2”
width=”200”
height=”75”
name=”HelloWorld”
align=”center”
vspace=”15”
alt=”The HelloWorld2 applet”>
<param name=”greeting” value=”Merry Christmas”>
<param name=”buttonLabel” value=”Click here”>
</applet>
</body>
</html>
Notice that this applet will be centered and have a vertical space of 15 pixels
above and below it in the browser. The HelloWorldApplet2 class is defined
next, and demonstrates how to use the getParameter() method to obtain the
values of the <param> tags. The event handling is done by the DisplayGreet-
ing class, which is also defined here.
Search WWH ::




Custom Search