博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
0311单利复利
阅读量:6254 次
发布时间:2019-06-22

本文共 4675 字,大约阅读时间需要 15 分钟。

package ch1;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.text.NumberFormat;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;public class fuli extends JFrame {    private static final long serialVersionUID = 3347254632537686808L;    private JLabel a1;             //标签    private JLabel a2;    private JLabel a3;    private JTextField b1;           //本金    private JTextField b2;           //利率    private JTextField b3;          //年份    private JButton c1;                 private JButton c2;    private JButton c3;    private JTextArea text;        // 显示纯文本的多行区域    public fuli() {        creatComponents();           //创建零件        layoutComponents();          //设计零件        registerHandlers();          //鼠标监控        setTitle("复利存款应用程序");        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        pack();    }    private void creatComponents() {        a1 = new JLabel("本 金 ");        a2 = new JLabel("年利率 ");        a3 = new JLabel("年 数 ");        b1 = new JTextField(10);        b2 = new JTextField(10);        b3 = new JTextField(10);        c1 = new JButton("复利");        c2 = new JButton("清除");        c3=new JButton("单利");        text = new JTextArea();    }    private void layoutComponents() {        setLayout(new FlowLayout());        JPanel panel1 = new JPanel();        panel1.add(a1);        panel1.add(b1);        JPanel panel2 = new JPanel();        panel2.add(a2);        panel2.add(b2);        JPanel panel3 = new JPanel();        panel3.add(a3);        panel3.add(b3);        JPanel panel4 = new JPanel();        panel4.add(c1);        panel4.add(c2);        panel4.add(c3);        JPanel leftpanel = new JPanel(new GridLayout(4, 1));        leftpanel.add(panel1);        leftpanel.add(panel2);        leftpanel.add(panel3);        leftpanel.add(panel4);        JScrollPane panel5 = new JScrollPane(text);        panel5.setPreferredSize(new Dimension(200, 150));        add(leftpanel);        add(panel5);    }    private void registerHandlers() {        c1ActionEventHander hander1 = new c1ActionEventHander();        c1.addActionListener(hander1);        c2ActionEventHander hander2 = new c2ActionEventHander();        c2.addActionListener(hander2);        c3ActionEventHander hander3=new c3ActionEventHander();        c3.addActionListener(hander3);    }    private class c1ActionEventHander implements ActionListener {        public void actionPerformed(ActionEvent e) {            double principal=0;            double amount;            double rate;            int n;            NumberFormat currencyformatter = NumberFormat.getCurrencyInstance();        //字符串转化为数字            String output = "年" + "/" + "复利存款";            int year = 1;            principal = Double.parseDouble(b1.getText());                            //字符串转化为数字            rate = Double.parseDouble(b2.getText());            n = Integer.parseInt(b3.getText());            while (year <= n) {                amount = principal * Math.pow(1 + rate, year);                output += String.valueOf(year) + "\t" + currencyformatter.format(amount) + "\n";                year = year + 1;            }            text.setText(output);        }    }    private class c2ActionEventHander implements ActionListener {        public void actionPerformed(ActionEvent e) {            b1.setText("");            b2.setText("");            b3.setText("");            text.setText("");        }    }    private class c3ActionEventHander implements ActionListener {        public void actionPerformed(ActionEvent e) {            double principal;            double amount;            double rate;            int n;            NumberFormat currencyformatter = NumberFormat.getCurrencyInstance();            String output = "年" + "/" + "单利存款";            int year = 1;            principal = Double.parseDouble(b1.getText());            rate = Double.parseDouble(b2.getText());            n = Integer.parseInt(b3.getText());            while (year <= n) {                amount = principal * (1 + rate* year);                output += String.valueOf(year) + "\t" + currencyformatter.format(amount) + "\n";                year = year + 1;            }            text.setText(output);        }    }    public static void main(String[] args) {        fuli frame = new fuli();        frame.setVisible(true);        frame.setSize(450, 200);        frame.setResizable(false);    }}

 

转载于:https://www.cnblogs.com/15linzhijie/p/5264372.html

你可能感兴趣的文章
SWT:获取字符串实际宽度
查看>>
Device Mapper Multipath(DM-Multipath)
查看>>
Web安全实践(10)攻击weblogic
查看>>
Xcode5.0使用iOS6.1SDK及模拟器
查看>>
如何编写解决方案?
查看>>
引起超时的原因及表解锁的方法<转>
查看>>
微信公众帐号开发教程第2篇-微信公众帐号的类型(普通和会议)(转)
查看>>
Oracle二三事之 EBS升级
查看>>
PC端体验效果最佳epub阅读器——iRead爱读书
查看>>
DataGridView打印类
查看>>
【java】实体类中 Set<对象> 按照对象的某个字段对set排序
查看>>
java基础之:匿名内部类应用例子一
查看>>
如何保证黑盒测试的覆盖率(转)
查看>>
spring jpa 实体互相引用返回restful数据循环引用报错的问题
查看>>
Android Butterknife 8.4.0 使用方法总结
查看>>
横向滑动的HorizontalListView滑动指定位置的解决方法
查看>>
c语言语系的命名风格和java系命名风格
查看>>
2013百度校招笔试真题以及解析(内存管理及其优缺点总结)
查看>>
Python Skelve 库
查看>>
自制DbHelper实现自动化数据库交互
查看>>