Java Reference
In-Depth Information
33
final int
FIELD_WIDTH =
10
;
34 rateField =
new
JTextField(FIELD_WIDTH);
35 rateField.setText(
ÐÑ
+ DEFAULT_RATE);
36 }
37
38
private void
createButton()
39 {
40 button =
new
JButton(
ÐAdd InterestÑ
);
41
42
class
AddInterestListener
implements
ActionListener
43 {
44
public void
actionPerformed(ActionEvent event)
45 {
46
double
rate = Double.parseDouble(
47 rateField.getText());
48
double
interest =
account.getBalance()
49 * rate /
100
;
50 account.deposit(interest);
51 resultLabel.setText(
52
Ðbalance: Ñ
+
account.getBalance());
53 }
54 }
55
56 ActionListener listener =
new
AddInterestListener();
57 button.addActionListener(listener);
58 }
59
60
private void
createPanel()
61 {
62 panel =
new
JPanel();
63 panel.add(rateLabel);
64 panel.add(rateField);
65 panel.add(button);
66 panel.add(resultLabel);
67 add(panel);
68 }
69
70
private
JLabel rateLabel;
71
private
JTextField rateField;
72
private
JButton button;