zoukankan      html  css  js  c++  java
  • 16.5

     1 import java.awt.*;
     2 import java.awt.event.ActionEvent;
     3 import java.awt.event.ActionListener;
     4 
     5 import javax.swing.*;
     6 
     7 public class Test_16_5 extends JFrame{
     8     private JTextField JT1 = new JTextField();
     9     private JTextField JT2 = new JTextField();
    10     private JTextField JT3 = new JTextField();
    11     private JTextField JT4 = new JTextField();
    12     private JLabel JL1 = new JLabel("investmentAmount");
    13     private JLabel JL2 = new JLabel("years");
    14     private JLabel JL3 = new JLabel("monthlyInterestRate");
    15     private JLabel JL4 = new JLabel("Future Value");
    16     private JButton JB = new JButton("Calculate");
    17     
    18     public Test_16_5(){
    19         JPanel JP1 = new JPanel(new GridLayout(4,2));
    20         JPanel JP2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    21         
    22         
    23         JP1.add(JL1);JP1.add(JT1);
    24         JP1.add(JL2);JP1.add(JT2);
    25         JP1.add(JL3);JP1.add(JT3);
    26         JP1.add(JL4);JP1.add(JT4);
    27         
    28         JP2.add(JB);
    29         add(JP1,BorderLayout.CENTER);
    30         add(JP2,BorderLayout.SOUTH);
    31         
    32         JB.addActionListener(new ComputeListener());
    33     }
    34     public static void main(String[] args) {
    35         // TODO Auto-generated method stub
    36         Test_16_5 T1 = new Test_16_5();
    37         T1.setTitle("Test_16.5");
    38         T1.pack();
    39         T1.setLocationRelativeTo(null);
    40         T1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    41         T1.setVisible(true);
    42     }
    43 
    44     class ComputeListener implements ActionListener{    
    45         
    46         @Override
    47         public void actionPerformed(ActionEvent e) {
    48             // TODO Auto-generated method stub
    49             double investmentAmount = Double.parseDouble(JT1.getText());
    50             int years = Integer.parseInt(JT2.getText());
    51             double monthlyInterestRate = Double.parseDouble(JT3.getText());
    52             Interests interes = new Interests(investmentAmount,monthlyInterestRate,years);
    53             JT4.setText(interes.getFutureValue()+"");
    54         }        
    55     }
    56     class Interests{
    57         private double inves;
    58         private double monthly;
    59         private int year;
    60         public Interests(double inves,double monthly,int year){
    61             this.inves = inves;
    62             this.year = year;
    63             this.monthly = monthly;
    64         }
    65         public double getFutureValue(){
    66             return inves*Math.pow(1+monthly, year*12);
    67         }
    68     }
    69     
    70 }
    Test_16_5.java

    效果图:

  • 相关阅读:
    python--第十天总结(Select/Poll/Epoll使用 )
    python--第九天总结
    数据库文件*.sdf文件定时备份,但是大小的增量在不断增长的问题排查
    打开和创建SqlCe(.sdf文件)
    C# 在RichTextBox中滚动鼠标时滚动的是父窗口的滚动条
    Foxmail 7.0破解版,拷贝到新机器后,发送邮件乱码问题
    C# RichTextBox设置行间距
    winform在鼠标操作时要判断是否按下Ctrl键
    vs2015 制作安装包额外需要安装的软件VSI_bundle
    vs 2015工具栏添加Tab Order
  • 原文地址:https://www.cnblogs.com/wanjiang/p/5636154.html
Copyright © 2011-2022 走看看