Java Reference
In-Depth Information
“trail,” you can define a new instance variable of the
PushCounterPanel
class as follows:
private
String display =
"
0
"
;
Then change the code in the
actionPerformed
method to be:
count++;
display = display + count;
label.setText("Pushes: " + display);
4.9
Text Fields
SR 4.34
In the
Fahrenheit
program, when a user types a number into the text
box of the interface and presses the Enter (or Return) key, the text
field component generates an action event. The
TempListener
class
that is listening for that event reacts by getting the text from the text
box, transforming the text into an integer that represents the given
Fahrenheit temperature, calculating the corresponding Celsius tempera-
ture and saving it to the
resultLabel
. The contents of the
resultLabel
then appear on the screen.
SR 4.35
To make the change to the
FahrenheitPanel
class, first remove the
outputLabel
from the class since it is no longer needed. Then, change
the code that sets the result label to:
String hold = text + " degrees Fahrenheit = ";
hold += celsiusTemp +
" degrees Celsius";
resultLabel.setText (hold);
Chapter 5
Conditionals and Loops
5.1
Boolean Expressions
SR 5.1
The flow of control through a program determines the program state-
ments that will be executed on a given run of the program.
SR 5.2
Each conditional and loop is based on a boolean condition that evalu-
ates to either true or false.
SR 5.3
The equality operators are equal (
==
) and not equal (
!=
). The relational
operators are less than (
<
), less than or equal to (
<=
), greater than (
>
),
and greater than or equal to (
>=
). The logical operators are not (
!
), and
(
&&
) and or (
||
).
Search WWH ::
Custom Search