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

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

package Fuli;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.Toolkit;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.JOptionPane;import javax.swing.JPanel;import javax.swing.JRadioButtonMenuItem;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 JLabel a4;    private JTextField b1; // 本金    private JTextField b2; // 利率    private JTextField b3; // 年份    private JTextField b4; // 期望值    private JButton c1;    private JButton c2;    private JButton c3;    private JTextArea text; // 显示纯文本的多行区域    private JPanel toolbar = new JPanel();    private JPanel toolbar2 = new JPanel();    boolean isadd = false;    JRadioButtonMenuItem mrButton = new JRadioButtonMenuItem("每年添加一定的本金");    public Fuli() {        setTitle("复利存款应用程序");        creatComponents(); // 创建零件        layoutComponents(); // 设计零件        registerHandlers(); // 鼠标监控        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        pack();    }    private void creatComponents() {        a1 = new JLabel("本 金 ");        a2 = new JLabel("年利率 ");        a3 = new JLabel("年 数 ");        a4 = new JLabel("期望值");        b1 = new JTextField(10);        b2 = new JTextField(10);        b3 = new JTextField(10);        b4 = 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 panel6 = new JPanel();        panel6.add(a4);        panel6.add(b4);        JPanel leftpanel = new JPanel(new GridLayout(3, 1));        leftpanel.add(panel1);        leftpanel.add(panel2);        leftpanel.add(panel3);        leftpanel.add(panel6);        JScrollPane panel5 = new JScrollPane(text);        panel5.setPreferredSize(new Dimension(400, 200));        toolbar.add(c1);        toolbar.add(c2);        toolbar.add(c3);        toolbar2.add(mrButton);        add(leftpanel);        // add(mrButton);        add(toolbar2, BorderLayout.NORTH);        add(panel5);        add(toolbar, BorderLayout.EAST);    }    private void registerHandlers() {        c1ActionEventHander hander1 = new c1ActionEventHander();        c1.addActionListener(hander1);        c2ActionEventHander hander2 = new c2ActionEventHander();        c2.addActionListener(hander2);        c3ActionEventHander hander3 = new c3ActionEventHander();        c3.addActionListener(hander3);        mrButtonActionEventHander hander4 = new mrButtonActionEventHander();        mrButton.addActionListener(hander4);    }    private class c1ActionEventHander 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()); // b1本金//            rate = Double.parseDouble(b2.getText()); // b2利率//            n = Integer.parseInt(b3.getText()); // b3年份//            amount = Double.parseDouble(b4.getText()); // b4期望值            int year = 1;//            rate = Double.parseDouble(b2.getText());//            n = Integer.parseInt(b3.getText());                            if (b1.getText().equals("")&& b2.getText() != null                    && b3.getText() != null && b4.getText() != null) {                                rate = Double.parseDouble(b2.getText());                n = Integer.parseInt(b3.getText());                    amount = Double.parseDouble(b4.getText());                    principal = 0;                    while (year <= n) {                        principal = amount / (Math.pow(1 + rate, year));                        year = year + 1;                    }                    output = "本金" + currencyformatter.format(principal) + "\n";                    text.setText(output);                            }            else if (b2.getText().equals("") && b1.getText() != null                    && b3.getText() != null && b4.getText() != null) // 求利率            {                principal = Double.parseDouble(b1.getText()); // b1本金                rate =0;                n = Integer.parseInt(b3.getText()); // b3年份                amount = Double.parseDouble(b4.getText()); // b4期望值                rate = java.lang.StrictMath.pow(amount / principal, 1.0 / n) - 1;                output = "利率" + rate + "\n";                text.setText(output);            }            else if (b3.getText().equals("") && b1.getText() != null                    && b2.getText() != null && b4.getText() != null) // 求年份            {                principal = Double.parseDouble(b1.getText()); // b1本金                amount = Double.parseDouble(b4.getText()); // b4期望值                rate = Double.parseDouble(b2.getText());                int n2=1;                  while(principal

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

你可能感兴趣的文章
App 卸载记录
查看>>
计算机网络与Internet应用
查看>>
Django 文件下载功能
查看>>
走红日本 阿里云如何能够赢得海外荣耀
查看>>
磁盘空间满引起的mysql启动失败:ERROR! MySQL server PID file could not be found!
查看>>
点播转码相关常见问题及排查方式
查看>>
[arm驱动]linux设备地址映射到用户空间
查看>>
弗洛伊德算法
查看>>
【算法之美】求解两个有序数组的中位数 — leetcode 4. Median of Two Sorted Arrays
查看>>
精度 Precision
查看>>
Android——4.2 - 3G移植之路之 APN (五)
查看>>
Linux_DHCP服务搭建
查看>>
[SilverLight]DataGrid实现批量输入(like Excel)(补充)
查看>>
秋式广告杀手:广告拦截原理与杀手组织
查看>>
翻译 | 摆脱浏览器限制的JavaScript
查看>>
闲扯下午引爆乌云社区“盗窃”乌云币事件
查看>>
02@在类的头文件中尽量少引入其他头文件
查看>>
JAVA IO BIO NIO AIO
查看>>
input checkbox 复选框大小修改
查看>>
BOOT.INI文件参数
查看>>