Java Reference
In-Depth Information
10 JFrame frame = new InvestmentFrame();
11 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
12 frame.setVisible( true );
13 }
14 }
ch10/textfield/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.JTextField;
8
9 /**
10 A frame that shows the growth of an investment with variable
interest.
11 */
12 public class InvestmentFrame extends JFrame
13 {
14 public InvestmentFrame()
15 {
16 account = new
BankAccount(INITIAL_BALANCE);
17
18 // Use instance fields for components
19 resultLabel = new JLabel( Ðbalance: Ñ +
account.getBalance());
20
21 // Use helper methods
22 createTextField();
23 createButton();
24 createPanel();
25
26 setSize(FRAME_WIDTH, FRAME_HEIGHT);
27 }
28
29 private void createTextField()
30 {
31 rateLabel = new JLabel( ÐInterest Rate:
Ñ );
32
481
482
Search WWH ::




Custom Search