复利计算器2.0

Posted Blac狼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了复利计算器2.0相关的知识,希望对你有一定的参考价值。

package JSQ;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Color;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

public class FuLiJiSuanQi extends JFrame {

/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField;
private JTextField textField_3;
private JLabel label_1;
double capital,year,rate,sum;
int tag;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FuLiJiSuanQi frame = new FuLiJiSuanQi();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public FuLiJiSuanQi() {
setTitle("\u590D\u5229\u8BA1\u7B97\u56682.0");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

final JLabel label = new JLabel("\u5B58\u6B3E(\u4E07):");
label.setFont(new Font("宋体", Font.PLAIN, 16));
label.setBounds(62, 96, 90, 15);
contentPane.add(label);

textField = new JTextField();
textField.setBounds(166, 84, 130, 21);
contentPane.add(textField);
textField.setColumns(10);
//x=textField.getText();

label_1 = new JLabel("\u5229\u7387( %):");
label_1.setFont(new Font("宋体", Font.PLAIN, 16));
label_1.setBounds(62, 142, 81, 15);
contentPane.add(label_1);

textField_1 = new JTextField();
textField_1.setBounds(166, 115, 130, 21);
contentPane.add(textField_1);
textField_1.setColumns(10);

JLabel label_2 = new JLabel("\u5E74\u9650(\u5E74):");
label_2.setFont(new Font("宋体", Font.PLAIN, 16));
label_2.setBounds(62, 117, 104, 15);
contentPane.add(label_2);

textField_2 = new JTextField();
textField_2.setBounds(166, 140, 130, 21);
contentPane.add(textField_2);
textField_2.setColumns(10);

final JButton btnNewButton = new JButton("\u672C\u606F(\u4E07)");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
capital=Double.parseDouble(textField.getText());
year=Double.parseDouble(textField_1.getText());
rate=Double.parseDouble(textField_2.getText());
if(tag==1)
{
sum=capital*Math.pow((1+rate/100),year);
}
else if(tag==0){
sum=capital*(1+rate/100)*year;
}
else {
sum=capital/Math.pow((1+rate/100),year);
}
textField_3.setText(Double.toString(sum));
}
});
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnNewButton.setBounds(53, 181, 90, 23);
contentPane.add(btnNewButton);

textField_3 = new JTextField();
textField_3.setForeground(new Color(127, 255, 212));
textField_3.setEnabled(false);
textField_3.setBounds(166, 182, 130, 21);
contentPane.add(textField_3);
textField_3.setColumns(10);

final JComboBox comboBox = new JComboBox();
comboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(comboBox.getSelectedItem().toString().equals("\u5355\u5229\u8BA1\u7B97"))
{
tag=0;
label.setText("\u5B58\u6B3E(\u4E07):");
btnNewButton.setText("\u672C\u606F(\u4E07)");
}
else if(comboBox.getSelectedItem().toString().equals("\u590D\u5229\u8BA1\u7B97")) {
tag=1;
label.setText("\u5B58\u6B3E(\u4E07):");
btnNewButton.setText("\u672C\u606F(\u4E07)");
}
else {
tag=3;
label.setText("总额(万):");
btnNewButton.setText("应存金额");
}
}
});
comboBox.setModel(new DefaultComboBoxModel(new String[] {"\u590D\u5229\u8BA1\u7B97", "\u5355\u5229\u8BA1\u7B97", "\u5B58\u94B1\u4F30\u7B97"}));
comboBox.setBounds(10, 10, 90, 21);
contentPane.add(comboBox);
}
}技术分享

以上是关于复利计算器2.0的主要内容,如果未能解决你的问题,请参考以下文章

复利计算 2.0

复利计算1.0,2.0

复利计算器2.0

复利计算2.0

复利计算2.0

复利计算1.0,2.0,3.0(补交)