Java Reference
In-Depth Information
73
private
JLabel resultLabel;
74
private
JPanel panel;
57
private
BankAccount account;
76
77
private static final int
FRAME_WIDTH =
500
;
78
private static final int
FRAME_HEIGHT =
200
;
79
80
private static final double
DEFAULT_RATE =
5
;
81
private static final double
INITIAL_BALANCE
=
1000
;
82 }
482
483
S
ELF
C
HECK
20.
What happens if you omit the first
JLabel
object?
21.
If a text field holds an integer, what expression do you use to read its
contents?
10.11 Text Areas
In
Section 10.10
, you saw how to construct text fields. A text field holds a single line
of text. To display multiple lines of text, use the
JTextArea
class.
Use a
JTextArea
to show multiple lines of text.
When constructing a text area, you can specify the number of rows and columns:
final int ROWS = 10;
final int COLUMNS = 30;
JTextArea textArea = new JTextArea(ROWS, COLUMNS);
Use the
setText
method to set the text of a text field or text area. The
append
method adds text to the end of a text area. Use newline characters to separate lines,
like this:
textArea.append(account.getBalance() + Ð\nÑ);
If you want to use a text field or text area for display purposes only, call the
setEditable
method like this