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
效果图:
相关文章推荐
- “欢迎使用CSDN-markdown编辑器”收藏
- 最短路径算法汇总
- Java 工程师的学习线路图。
- 2、keys相关命令
- 好番记录
- [shiro] Wildcard string cannot be null or empty. Make sure permission strings are properly formatted.
- 使用工具优化 msql 5.6 的配置
- Java设计模式之单例模式
- Codeforces Round #360 (Div. 2) -- D. Remainders Game (中国剩余定理)
- 平衡二叉树(AVL)树
- Zookeeper实战之单机模式
- 学习VMware虚拟化技术
- HDU2021 发工资咯:)
- PHP购物车代码
- 结构体内字节对齐偏移量
- 算法导论 第15章 动态规划:15.1钢条切割
- Ubuntu下查看软件版本及安装位置
- PIXHAWK源码分析之二—Hello Sky(PIXHAWK读取姿态数据并且显示)
- [编程题] 有趣的数字
- 319. Bulb Switcher