Java Reference
In-Depth Information
calling their components label, title, or name. This convention makes it difficult
to remember and identify what kind of component is being used in longer
programs.
In this program, the naming convention utilized is to have a word beginning
with a lowercase letter to identify the purpose of the component, followed by the
component name in title case. A Label, for example, might be named costLabel;
a TextField might be named amountField. The naming conventions for a Button
use a verb or a response caption, such as OK. The verb or response will be fol-
lowed by the word Button. For example, a button might be named calcButton
or okButton. Whatever naming convention you decide to use in your own pro-
grams, it should provide for easy reading and consistency.
Recall in the previous versions of the Body Mass Index Calculator program
you indented related lines of code, such as the lines following the user prompt
that read and parsed input data. This kind of indentation rule is part of a pro-
grammer's coding convention . The program code for the Body Mass Index
Calculator applet follows the same coding conventions, indenting the compo-
nent constructors for TextFields associated with prompt Labels. Java currently
provides no specific rules about coding conventions; as Java takes a firmer hold
in application development, a system of standardized indentations and spacing
will follow. For now, as with naming conventions, coding conventions should
provide for easy reading, logical grouping, and consistency.
Perform the following step to construct Label, TextField, and Button
components in the applet.
To Add Interface Components to an Applet
1. With the insertion point on line 21, enter the code as shown in
Figure 3-39 on page 3.55 to construct the components.
The code to construct the components is displayed in the coding window
(Figure 3-40).
component
constructor
code entered
FIGURE 3-40
Search WWH ::




Custom Search