Java Reference
In-Depth Information
127
private
JTextArea display;
128
129
private
ATM theATM;
130
131
private static final int
FRAME_WIDTH =
300
;
132
private static final int
FRAME_HEIGHT =
300
;
133 }
This class uses layout managers to arrange the text field and the keypad buttons.
See
Chapter 18
for more information about layout managers.
ch12/atm/KeyPad.java
1
import
java.awt.BorderLayout;
2
import
java.awt.GridLayout;
3
import
java.awt.event.ActionEvent;
4
import
java.awt.event.ActionListener;
5
import
javax.swing.JButton;
6
import
javax.swing.JPanel;
7
import
javax.swing.JTextField;
8
9 /**
10
A component that lets the user enter a number, using
11
a keypad labeled with digits.
12 */
13
public class
KeyPad
extends
JPanel
14 {
15 /**
16
Constructs the keypad panel.
17 */
18
public
KeyPad()
19 {
20 setLayout(
new
BorderLayout());
21
22 //
Add display field
23
24 display =
new
JTextField();
25 add(display,
ÐNorthÑ
);
26
27 //
Make button panel
574
575