您的位置:首页 > 其它

事件驱动器计算投资的未来值

2012-12-10 17:17 134 查看
/**
*
*/
package Lyt;

import javax.swing.JFrame;

/**
* @author Administrator
*
*/
public class lyt {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
showNum frame=new showNum();
frame.setTitle("未来值计算");
frame.setSize(300,120);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

}

/**
*
*/
package Lyt;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class showNum extends JFrame{
JTextField Amount=new JTextField();
JTextField Year=new JTextField();
JTextField Rate=new JTextField();
JTextField Future_value=new JTextField();
JButton Caculate=new JButton("Caculate");
public showNum()
{
JPanel p1=new JPanel(new GridLayout(5,2));
p1.add(new JLabel("Investument Amount"));
p1.add(Amount);
p1.add(new JLabel("Year"));
p1.add(Year);
p1.add(new JLabel("Annual Interest Rate"));
p1.add(Rate);
p1.add(new JLabel("Future value"));
p1.add(Future_value);
p1.add(Caculate);
add(p1);
Caculate.addActionListener(new ButtonListener());
}
private class ButtonListener implements ActionListener {

public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double sum=0;
double a=Double.parseDouble(Amount.getText());
double b=Double.parseDouble(Year.getText());
double c=Double.parseDouble(Rate.getText())/100.0/12;
sum=a*Math.pow((1+c),b*12);
Future_value.setText(String.format("%.2f", sum));

}
}

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