Java Reference
In-Depth Information
ch10/textarea/InvestmentFrame.java
1
import
java.awt.event.ActionEvent;
2
import
java.awt.event.ActionListener;
3
import
javax.swing.JButton;
4
import
javax.swing.JFrame;
5
import
javax.swing.JLabel;
6
import
javax.swing.JPanel;
7
import
javax.swing.JScrollPane;
8
import
javax.swing.JTextArea;
9
import
javax.swing.JTextField;
10
11 /**
12
A frame that shows the growth of an investment with variable
interest.
13 */
14
public class
InvestmentFrame
extends
JFrame
15 {
16
public
InvestmentFrame()
17 {
18 account =
new
BankAccount(INITIAL_BALANCE);
19 resultArea =
new
JTextArea(AREA_ROWS,
AREA_COLUMNS);
20 resultArea.setEditable(false);
21
22 //
Use helper methods
23 createTextField();
24 createButton();
25 createPanel();
26
27 setSize(FRAME_WIDTH, FRAME_HEIGHT);
28 }
29
30
private void
createTextField()
31 {
32 rateLabel =
new
JLabel(ÐInterest Rate:
Ñ);
33
34
final int
FIELD_WIDTH =
10
;
35 rateField =
new
JTextField(FIELD_WIDTH);
36 rateField.setText(
ÐÑ
+ DEFAULT_RATE);
37 }
484
485