您的位置:首页 > 其它

16.5

2016-07-02 22:13 295 查看
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Test_16_5 extends JFrame{
private JTextField JT1 = new JTextField();
private JTextField JT2 = new JTextField();
private JTextField JT3 = new JTextField();
private JTextField JT4 = new JTextField();
private JLabel JL1 = new JLabel("investmentAmount");
private JLabel JL2 = new JLabel("years");
private JLabel JL3 = new JLabel("monthlyInterestRate");
private JLabel JL4 = new JLabel("Future Value");
private JButton JB = new JButton("Calculate");

public Test_16_5(){
JPanel JP1 = new JPanel(new GridLayout(4,2));
JPanel JP2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));

JP1.add(JL1);JP1.add(JT1);
JP1.add(JL2);JP1.add(JT2);
JP1.add(JL3);JP1.add(JT3);
JP1.add(JL4);JP1.add(JT4);

JP2.add(JB);
add(JP1,BorderLayout.CENTER);
add(JP2,BorderLayout.SOUTH);

JB.addActionListener(new ComputeListener());
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Test_16_5 T1 = new Test_16_5();
T1.setTitle("Test_16.5");
T1.pack();
T1.setLocationRelativeTo(null);
T1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
T1.setVisible(true);
}

class ComputeListener implements ActionListener{

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double investmentAmount = Double.parseDouble(JT1.getText());
int years = Integer.parseInt(JT2.getText());
double monthlyInterestRate = Double.parseDouble(JT3.getText());
Interests interes = new Interests(investmentAmount,monthlyInterestRate,years);
JT4.setText(interes.getFutureValue()+"");
}
}
class Interests{
private double inves;
private double monthly;
private int year;
public Interests(double inves,double monthly,int year){
this.inves = inves;
this.year = year;
this.monthly = monthly;
}
public double getFutureValue(){
return inves*Math.pow(1+monthly, year*12);
}
}

}


Test_16_5.java
效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: