复利计算

摘要:
packagefulijisuan;importjava.applet.Applet;importjava.awt.Button;importjava.awt.Checkbox;importjava.awt.CheckboxGroup;importjava.awt.Color;importjava.awt.Dimension;importjava.awt.Font;importjava.awt.e
package fulijisuan;

import java.applet.Applet;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public classfulijisuan1 extends Applet implements ActionListener, MouseListener, ItemListener {

    static JTextField jTextmoney = newJTextField();

    static JTextField jTextrate = newJTextField();

    static JTextField jTextyears = newJTextField();

    static JTextField jTextfinally = newJTextField();

    static JTextField jTextResult = newJTextField();

    static JLabel jLabletitle = new JLabel("复利计算器");

    static JLabel jLablemoney = new JLabel("本金");

    static JLabel jLablerate = new JLabel("利率");

    static JLabel jLableyears = new JLabel("年期");

    static JLabel jLablefinally = new JLabel("终值");

    JLabel jLableResult = new JLabel("结果");

    static calculate calculate = newcalculate();

    Button b1 = new Button("确认");

    Button b2 = new Button("清除");

    Checkbox ckbHB[] = new Checkbox[8];

    CheckboxGroup ckgHB = newCheckboxGroup();

    public void init() //初始化,堆砌界面
{
        setLayout(null); //不设布局管理器
setBackground(new Color(255, 250, 150));

        addMouseListener(this);//将本类作为鼠标事件的接口响应鼠标动作
        add(b1); //将事先定义好的第一个按钮添加入界面
        b1.setBounds(350, 350, 100, 50); //设置第一个按钮左上角的位置和大小
        b1.addActionListener(this);//将本类作为按钮事件的接口响应按钮动作
add(b2);
        b2.setBounds(350, 400, 100, 50);
        b2.addActionListener(this);

        add(jTextmoney);
        jTextmoney.setBounds(100, 140, 220, 30);
        jTextmoney.addActionListener(this);

        add(jTextrate);
        jTextrate.setBounds(100, 190, 220, 30);
        jTextrate.addActionListener(this);

        add(jTextyears);
        jTextyears.setBounds(100, 240, 220, 30);
        jTextyears.addActionListener(this);

        add(jTextfinally);
        jTextfinally.setBounds(100, 290, 220, 30);
        jTextfinally.addActionListener(this);

        add(jTextResult);
        jTextResult.setBounds(550, 10, 440, 450);
        jTextResult.addActionListener(this);

        add(jLabletitle);
        jLabletitle.setBounds(100, 30, 200, 50);
        jLabletitle.setForeground(Color.red);
        jLabletitle.setFont(new Font("微软雅黑", Font.BOLD, 30));

        add(jLablemoney);
        jLablemoney.setBounds(50, 140, 30, 30);

        add(jLablerate);
        jLablerate.setBounds(50, 190, 30, 30);

        add(jLableyears);
        jLableyears.setBounds(50, 240, 30, 30);

        add(jLablefinally);
        jLablefinally.setBounds(50, 290, 30, 30);

        add(jLableResult);
        jLableResult.setBounds(500,10, 30, 30);

        jTextResult.setEditable(false);

        ckbHB[0] = new Checkbox("求总额复利", ckgHB, false);
        ckbHB[0].setBounds(350, 20, 100, 40);
        ckbHB[1] = new Checkbox("求总额单利", ckgHB, false);
        ckbHB[1].setBounds(350, 60, 100, 40);
        ckbHB[2] = new Checkbox("求本金", ckgHB, false);
        ckbHB[2].setBounds(350, 100, 100, 40);
        ckbHB[3] = new Checkbox("求年期", ckgHB, false);
        ckbHB[3].setBounds(350, 140, 100, 40);
        ckbHB[4] = new Checkbox("求利率", ckgHB, false);
        ckbHB[4].setBounds(350, 180, 100, 40);
        ckbHB[5] = new Checkbox("若连本带利投资,最后得到的资产总值", ckgHB, false);
        ckbHB[5].setBounds(350, 220, 100, 40);
        ckbHB[6] = new Checkbox("若投资本金每年不变,最后得到的资产总值", ckgHB, false);
        ckbHB[6].setBounds(350, 260, 100, 40);
        ckbHB[7] = new Checkbox("银行贷款", ckgHB, false);
        ckbHB[7].setBounds(350, 300, 100, 40);
        add(ckbHB[0]);
        add(ckbHB[1]);
        add(ckbHB[2]);
        add(ckbHB[3]);
        add(ckbHB[4]);
        add(ckbHB[5]);
        add(ckbHB[6]);
        add(ckbHB[7]);
        ckbHB[0].addItemListener(this);
        ckbHB[1].addItemListener(this);
        ckbHB[2].addItemListener(this);
        ckbHB[3].addItemListener(this);
        ckbHB[4].addItemListener(this);
        ckbHB[5].addItemListener(this);
        ckbHB[6].addItemListener(this);
        ckbHB[7].addItemListener(this);

        this.resize(new Dimension(1000, 500));

    }

    public voidenable(boolean e) {
        //设置组件状态
b1.setEnabled(e);
        b2.setEnabled(e);
        ckbHB[0].setEnabled(e);
        ckbHB[1].setEnabled(e);
        ckbHB[2].setEnabled(e);
        ckbHB[3].setEnabled(e);
        ckbHB[4].setEnabled(e);
        ckbHB[5].setEnabled(e);
        ckbHB[6].setEnabled(e);
        ckbHB[7].setEnabled(e);

    }

    public static voidreducingState() {
        //清除文本框的值
        jTextmoney.setVisible(true);
        jLablemoney.setVisible(true);
        jTextrate.setVisible(true);
        jLablerate.setVisible(true);
        jTextyears.setVisible(true);
        jLableyears.setVisible(true);
        jTextfinally.setVisible(true);
        jLablefinally.setVisible(true);
    }

    @Override
    public voiditemStateChanged(ItemEvent arg0) {
        //做完选择后的变化
        if (ckbHB[0].getState()) {
            fulijisuan1.reducingState();
            jTextfinally.setVisible(false);
            jLablefinally.setVisible(false);
        } else if (ckbHB[1].getState()) {
            fulijisuan1.reducingState();
            jTextfinally.setVisible(false);
            jLablefinally.setVisible(false);
        } else if (ckbHB[2].getState()) {
            fulijisuan1.reducingState();
            jTextmoney.setVisible(false);
            jLablemoney.setVisible(false);
        } else if (ckbHB[3].getState()) {
            fulijisuan1.reducingState();
            jTextyears.setVisible(false);
            jLableyears.setVisible(false);
        } else if (ckbHB[4].getState()) {
            fulijisuan1.reducingState();
            jTextrate.setVisible(false);
            jLablerate.setVisible(false);
        } else if (ckbHB[5].getState()) {
            fulijisuan1.reducingState();
            jTextfinally.setVisible(false);
            jLablefinally.setVisible(false);
        } else if (ckbHB[6].getState()) {
            fulijisuan1.reducingState();
            jTextfinally.setVisible(false);
            jLablefinally.setVisible(false);
        } else if (ckbHB[7].getState()) {
            fulijisuan1.reducingState();
            jTextfinally.setVisible(false);
            jLablefinally.setVisible(false);
        }

    }

    @Override
    public voidmouseClicked(MouseEvent arg0) {

    }

    @Override
    public voidmouseEntered(MouseEvent arg0) {

    }

    @Override
    public voidmouseExited(MouseEvent arg0) {

    }

    @Override
    public voidmousePressed(MouseEvent arg0) {

    }

    @Override
    public voidmouseReleased(MouseEvent arg0) {

    }

    @Override
    public voidactionPerformed(ActionEvent e) {
        //确定后显示结果和清除文本框的值
        if (e.getSource() ==b1) {
            double money = 0;
            double rate = 0;
            double years = 0;
            double Finally = 0;
            try{
                jTextResult.setText("");
                if (ckbHB[0].getState()) {
                    //总额复利
                    money =Double.valueOf(jTextmoney.getText().toString()).doubleValue();
                    rate =Double.valueOf(jTextrate.getText().toString()).doubleValue();
                    years =Double.valueOf(jTextyears.getText().toString()).doubleValue();
                    Finally =calculate.calculatezongefuli(money, rate, years);
                    jTextResult.setText(Double.toString(Finally));

                } else if (ckbHB[1].getState()) {
                    //总额单利
                    money =Double.valueOf(jTextmoney.getText().toString()).doubleValue();
                    rate =Double.valueOf(jTextrate.getText().toString()).doubleValue();
                    years =Double.valueOf(jTextyears.getText().toString()).doubleValue();
                    Finally =calculate.calculatezongedanli(money, rate, years);
                    jTextResult.setText(Double.toString(Finally));

                } else if (ckbHB[2].getState()) {
                    //本金
                    rate =Double.valueOf(jTextrate.getText().toString()).doubleValue();
                    years =Double.valueOf(jTextyears.getText().toString()).doubleValue();
                    Finally =Double.valueOf(jTextfinally.getText().toString()).doubleValue();
                    money =calculate.calculatebenjin(rate, years, Finally);
                    jTextResult.setText(Double.toString(money));

                } else if (ckbHB[3].getState()) {
                    //期限
                    money =Double.valueOf(jTextmoney.getText().toString()).doubleValue();
                    rate =Double.valueOf(jTextrate.getText().toString()).doubleValue();
                    Finally =Double.valueOf(jTextfinally.getText().toString()).doubleValue();
                    years =calculate.calculatenianqi(money, rate, Finally);
                    jTextResult.setText(Double.toString(years));

                } else if (ckbHB[4].getState()) {
                    //利率
                    money =Double.valueOf(jTextmoney.getText().toString()).doubleValue();
                    years =Double.valueOf(jTextyears.getText().toString()).doubleValue();
                    Finally =Double.valueOf(jTextfinally.getText().toString()).doubleValue();
                    rate =calculate.calculaterate(money, years, Finally);
                    jTextResult.setText(Double.toString(rate));
                } else if (ckbHB[5].getState()) {
                    //若连本带利投资,最后得到的资产总值
                    money =Double.valueOf(jTextmoney.getText().toString()).doubleValue();
                    rate =Double.valueOf(jTextrate.getText().toString()).doubleValue();
                    years =Double.valueOf(jTextyears.getText().toString()).doubleValue();
                    Finally =calculate.calculatemoneyandrate(money, rate, years);
                    jTextResult.setText(Double.toString(Finally));
                } else if (ckbHB[6].getState()) {
                    //若投资本金每年不变,最后得到的资产总值
                    money =Double.valueOf(jTextmoney.getText().toString()).doubleValue();
                    rate =Double.valueOf(jTextrate.getText().toString()).doubleValue();
                    years =Double.valueOf(jTextyears.getText().toString()).doubleValue();
                    Finally =calculate.calculatemoney(money, rate, years);
                    jTextResult.setText(Double.toString(Finally));

                } else if (ckbHB[7].getState()) {
                    //银行贷款
                    money =Double.valueOf(jTextmoney.getText().toString()).doubleValue();
                    rate =Double.valueOf(jTextrate.getText().toString()).doubleValue();
                    years =Double.valueOf(jTextyears.getText().toString()).doubleValue();
                    Finally =calculate.calculatedaikuan(money, rate, years);
                    jTextResult.setText(Double.toString(Finally));

                }
            } catch(Exception e1) {
                JOptionPane.showMessageDialog(null, "未输入正确的数据!", "错误提示", JOptionPane.ERROR_MESSAGE);
                System.out.println(e1);
            }
        }

        if (e.getSource() ==b2) {
            jTextfinally.setText("");
            jTextmoney.setText("");
            jTextrate.setText("");
            jTextyears.setText("");
            jTextResult.setText("");
        }
    }
}

此次的复利计算并没有多大的变化,就多了个结果窗口弹出,把界面做的更好看些。

免责声明:文章转载自《复利计算》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇c#排序sql语句查询用git如何把单个文件回退到某一版本下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

关闭cursor的几个注意点

对关闭cursor的案例: 案例1: Cursor mCursor = query(...); 关闭方法:最好用 Try{ ...... }finally{ If(mCursor != null) mCursor.close(); } 因为可能会在关闭cursor前 直接return,那么这个cursor就没有被关闭。而final...

守护线程会不会执行finally?默认情况new thread怎么样确定守护状态?

finally throw return 中,线程的状态及interrupt 守护线程在退出的时候并不会执行finnaly块中的代码 线程池造成服务器内存泄漏 中所述,新建线程默认上使用建立线程时的当前线程所处的守护状态 本文予以验证: package fin; /** * Created by joyce on 2019/12/16. */ pub...