1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
public class BalanceApplet extends JApplet implements ActionListener {
double invest;
double interRate;
int numbsyears;
Container con = getContentPane();
JLabel displaytext1 = new JLabel("Welcome to TD Bank");
JLabel displaytext2 = new JLabel("Investment:");
JLabel displaytext3 = new JLabel("Interet Rate:");
JLabel displaytext4 = new JLabel("numbs years:");
Font headlineFont1 = new Font ("helvetica",Font.BOLD,16);
Font headlineFont2 = new Font ("helvetica",Font.BOLD,10);
Font headlineFont3 = new Font ("helvetica",Font.BOLD,10);
Font headlineFont4 = new Font ("helvetica",Font.BOLD,10);
JTextField enter1 = new JTextField(5);
JTextField enter2 = new JTextField(5);
JTextField enter3 = new JTextField(5);
TextArea result = new TextArea(2,25);
JButton CalculateJButton = new JButton("Calculate");
public void init(){
displaytext1.setFont(headlineFont1);
displaytext2.setFont(headlineFont2);
displaytext3.setFont(headlineFont3);
displaytext4.setFont(headlineFont4);
result = new TextArea(4,25);
result.setEditable(false);
con.add(displaytext1);
con.add(displaytext2);
con.add(displaytext3);
con.add(displaytext4);
con.add(enter1);
con.add(enter2);
con.add(enter3);
con.add(CalculateJButton);
con.setLayout(new FlowLayout());
con.add(result);
CalculateJButton.addActionListener(this);
enter1.addActionListener(this);
enter2.addActionListener(this);
enter2.addActionListener(this);
System.out.println("init");
}
public void actionPerformed(ActionEvent e) {
Double invest = new Double (enter1.getText());
Double interRate = new Double( enter2.getText());
Integer numbsyears = new Integer ( enter3.getText());
for( int i=0 ;i<= numbsyears; i++){
result.setText((i + "==" +(invest)));
System.out.println(i + "==" +(invest));
invest+=interRate*invest;
validate();
}
}
public void start( )
{
System.out.println("start");
}
public void stop( )
{
System.out.println("stop");
}
public void destroy( )
{
System.out.println("destroy");
}
} |
Partager