Let us begin with a quick review of some basic terminology. Programs manipulate window controls by sending
them messages. For instance,
Asking a control for information or telling it what to do is called
sending the control a message. Sending a control a message activates in the
control a method that accomplishes the desired task.
Methods are implemented by Java code. Thus,
with respect to the statement
| Type of Control
|
Name of Method
|
What the Method
Does
|
| IntegerField
|
setNumber(anInteger)
returns void
|
Displays anInteger
on the screen. Nothing is returned.
|
|
|
getNumber()
returns double
|
If the number on
the screen is a valid integer, then reads the number and returns it. If the number is not a valid integer, then sets it
to 0 and returns 0.
|
|
|
isValid()
returns boolean
|
Determines if the
number entered on the screen is a valid integer. More
about Booleans later.
|
| DoubleField
|
setNumber(aDouble)
returns void
|
Displays aDouble
on the screen. Nothing is returned.
|
|
|
getNumber()
returns double
|
If the number on
the screen is a valid double, then reads the number and returns it. If the number is not a valid double, then sets it
to 0 and returns 0.
|
|
|
isValid()
returns boolean
|
Determines if the
number entered on the screen is a valid double.
|
|
|
setPrecision(anInteger)
returns void
|
Sets the
controls precision to the specified number.
When a double is displayed on the screen, the number of digits after
the decimal point is equal to the precision.
If the precision is never set or if it is set to -1, then the format
of the number on the screen varies and depends on the size of the number; however, at most
six digits will be displayed.
|
|
|
getPrecision()
returns int
|
Returns the value
of the precision
|
| Label
|
getText()
returns String
|
Returns the text of
the label. Such text is called a string.
|
|
|
setText(aString)
returns void
|
Sets the text of
the label to the specified string
|
| Button
|
setLabel(aString)
returns void
|
Sets the text
written on the button to the specified string
|
|
|
getLabel()
returns String
|
Returns the text
written on the button.
|
| All Window Controls
|
setVisible(true/false)
returns void
|
If false then hides
the control so that the user can no longer see it on the screen.
If true then makes the control visible again.
|
| setEnabled (true/false)
returns void
|
If false then
disable the control for user input.
If true then enable the control for user input.
Default is enabled.
|
| requestFocus()
returns void
|
Moves the focus to
the control
|