import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test5 extends JFrame implements WindowListener,ActionListener{
    JLabel jl1=new JLabel("本金");
    JLabel jl2=new JLabel("利率");
    JLabel jl3=new JLabel("存款年数");
    JLabel jl4=new JLabel("每年年金额总计");
    JTextField jt1=new JTextField(10);
    JTextField jt2=new JTextField(10);
    JTextField jt3=new JTextField(10);
    JTextArea ja1=new JTextArea(4,6);
    JButton jbtnAdd=new JButton("计算");
           public Test5(String s) {
        super(s);
      Container jfrm=getContentPane();
      
       JPanel p1=new JPanel();
       p1.setLayout(new GridLayout(3,2));
       JPanel p2=new JPanel();
       p2.setLayout(new GridLayout(2,1));
       p1.add(jl1);
       p1.add(jt1);
       p1.add(jl2);
       p1.add(jt2);
       p1.add(jl3);
       p1.add(jt3);
       jfrm.add(p1,BorderLayout.WEST);
       p2.add(jl4);
       p2.add(ja1);
       jfrm.add(p2,BorderLayout.SOUTH);
       jfrm.add(jbtnAdd,BorderLayout.EAST);
       addWindowListener(this);
       jbtnAdd.addActionListener(this);
    }
    public static void main(String[] args) {
        Test5 t=new Test5("计算");
        t.setSize(400,300);
        t.setVisible(true);
    }    public void windowOpened(WindowEvent e) {
    }    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }    public void windowClosed(WindowEvent e) {
    }    public void windowIconified(WindowEvent e) {
    }    public void windowDeiconified(WindowEvent e) {
    }    public void windowActivated(WindowEvent e) {
    }    public void windowDeactivated(WindowEvent e) {
    }    public void actionPerformed(ActionEvent e) {
        double sum=1,nu1,nu2,nu3;
       
        nu1=(double)Integer.parseInt(jt1.getText());
        nu2=(double)Integer.parseInt(jt2.getText());
        nu3=(double)Integer.parseInt(jt3.getText());
        sum=sum*nu1*(1.0f+nu2);
        for(int i=1;i<Integer.parseInt(jt3.getText());i++)
            sum=sum*(1.0f+nu2);
        ja1.setText(String.valueOf(sum));
        
       
    }
}
以上是原代码