Java Reference
In-Depth Information
LISTING B.1
Continued
16: String[] p3 = { “Version”, “int”, “Version number” };
17: String[][] response = { p1, p2, p3 };
18: return response;
19: }
20:
21: public void init() {
22: name = getParameter(“Name”);
23: date = getParameter(“Date”);
24: String versText = getParameter(“Version”);
25: if (versText != null) {
26: version = Integer.parseInt(versText);
27: }
28: }
29:
30: public void paint(Graphics screen) {
31: Graphics2D screen2D = (Graphics2D) screen;
32: screen2D.drawString(“Name: “ + name, 5, 50);
33: screen2D.drawString(“Date: “ + date, 5, 100);
34: screen2D.drawString(“Version: “ + version, 5, 150);
35: }
36: }
B
The main function of this applet is to display the value of three parameters:
Name
,
Date
,
and
Version
. The
getAppletInfo()
method returns the following string:
This applet demonstrates the use of the Applet's Info feature.
The
getParameterInfo()
method is a bit more complicated if you haven't worked with
multidimensional arrays. The following things are taking place:
Line 13 defines the return type of the method as a two-dimensional array of
String
objects.
n
Line 14 creates an array of
String
objects with three elements: “Name”, “String”,
and “Programmer's Name”. These elements describe one of the parameters that
can be defined for the
AppInfo
applet. They describe the name of the parameter
(
Name
in this case), the type of data that the parameter will hold (a string), and a
description of the parameter (“Programmer's Name”). The three-element array is
stored in the
p1
object.
n
Lines 15-16 define two more
String
arrays for the
Date
and
Version
parameters.
n
Line 17 uses the
response
object to store an array that contains three string arrays:
p1
,
p2
, and
p3
.
n
Line 18 uses the
response
object as the method's return value.
n