复利计算器2.0

  1 package JSQ;
  2 
  3 import java.awt.EventQueue;
  4 
  5 import javax.swing.JFrame;
  6 import javax.swing.JPanel;
  7 import javax.swing.border.EmptyBorder;
  8 import javax.swing.JLabel;
  9 import javax.swing.JTextField;
 10 import javax.swing.JButton;
 11 import java.awt.event.ActionListener;
 12 import java.awt.event.ActionEvent;
 13 import java.awt.Font;
 14 import java.awt.event.MouseAdapter;
 15 import java.awt.event.MouseEvent;
 16 import java.awt.Color;
 17 import javax.swing.JComboBox;
 18 import javax.swing.DefaultComboBoxModel;
 19 import java.awt.event.ItemListener;
 20 import java.awt.event.ItemEvent;
 21 
 22 public class FuLiJiSuanQi extends JFrame {
 23 
 24 /**
 25 * 
 26 */
 27 private static final long serialVersionUID = 1L;
 28 private JPanel contentPane;
 29 private JTextField textField_1;
 30 private JTextField textField_2;
 31 private JTextField textField;
 32 private JTextField textField_3;
 33 private JLabel label_1;
 34 double capital,year,rate,sum;
 35 int tag;
 36 /**
 37 * Launch the application.
 38 */
 39 public static void main(String[] args) {
 40 EventQueue.invokeLater(new Runnable() {
 41 public void run() {
 42 try {
 43 FuLiJiSuanQi frame = new FuLiJiSuanQi();
 44 frame.setVisible(true);
 45 } catch (Exception e) {
 46 e.printStackTrace();
 47 }
 48 }
 49 });
 50 }
 51 
 52 /**
 53 * Create the frame.
 54 */
 55 public FuLiJiSuanQi() {
 56 setTitle("u590Du5229u8BA1u7B97u56682.0");
 57 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 58 setBounds(100, 100, 450, 300);
 59 contentPane = new JPanel();
 60 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
 61 setContentPane(contentPane);
 62 contentPane.setLayout(null);
 63 
 64 final JLabel label = new JLabel("u5B58u6B3E(u4E07):");
 65 label.setFont(new Font("宋体", Font.PLAIN, 16));
 66 label.setBounds(62, 96, 90, 15);
 67 contentPane.add(label);
 68 
 69 textField = new JTextField();
 70 textField.setBounds(166, 84, 130, 21);
 71 contentPane.add(textField);
 72 textField.setColumns(10);
 73 //x=textField.getText();
 74 
 75 label_1 = new JLabel("u5229u7387( %):");
 76 label_1.setFont(new Font("宋体", Font.PLAIN, 16));
 77 label_1.setBounds(62, 142, 81, 15);
 78 contentPane.add(label_1);
 79 
 80 textField_1 = new JTextField();
 81 textField_1.setBounds(166, 115, 130, 21);
 82 contentPane.add(textField_1);
 83 textField_1.setColumns(10);
 84 
 85 JLabel label_2 = new JLabel("u5E74u9650(u5E74):");
 86 label_2.setFont(new Font("宋体", Font.PLAIN, 16));
 87 label_2.setBounds(62, 117, 104, 15);
 88 contentPane.add(label_2);
 89 
 90 textField_2 = new JTextField();
 91 textField_2.setBounds(166, 140, 130, 21);
 92 contentPane.add(textField_2);
 93 textField_2.setColumns(10);
 94 
 95 final JButton btnNewButton = new JButton("u672Cu606F(u4E07)");
 96 btnNewButton.addMouseListener(new MouseAdapter() {
 97 @Override
 98 public void mouseClicked(MouseEvent e) {
 99 capital=Double.parseDouble(textField.getText());
100 year=Double.parseDouble(textField_1.getText());
101 rate=Double.parseDouble(textField_2.getText());
102 if(tag==1)
103 {
104 sum=capital*Math.pow((1+rate/100),year);
105 }
106 else if(tag==0){
107 sum=capital*(1+rate/100)*year;
108 }
109 else {
110 sum=capital/Math.pow((1+rate/100),year);
111 }
112 textField_3.setText(Double.toString(sum));
113 }
114 });
115 btnNewButton.addActionListener(new ActionListener() {
116 public void actionPerformed(ActionEvent e) {
117 }
118 });
119 btnNewButton.setBounds(53, 181, 90, 23);
120 contentPane.add(btnNewButton);
121 
122 textField_3 = new JTextField();
123 textField_3.setForeground(new Color(127, 255, 212));
124 textField_3.setEnabled(false);
125 textField_3.setBounds(166, 182, 130, 21);
126 contentPane.add(textField_3);
127 textField_3.setColumns(10);
128 
129 final JComboBox comboBox = new JComboBox();
130 comboBox.addItemListener(new ItemListener() {
131 public void itemStateChanged(ItemEvent e) {
132 if(comboBox.getSelectedItem().toString().equals("u5355u5229u8BA1u7B97"))
133 {
134 tag=0;
135 label.setText("u5B58u6B3E(u4E07):");
136 btnNewButton.setText("u672Cu606F(u4E07)");
137 }
138 else if(comboBox.getSelectedItem().toString().equals("u590Du5229u8BA1u7B97")) {
139 tag=1;
140 label.setText("u5B58u6B3E(u4E07):");
141 btnNewButton.setText("u672Cu606F(u4E07)");
142 }
143 else {
144 tag=3;
145 label.setText("总额(万):");
146 btnNewButton.setText("应存金额");
147 }
148 }
149 });
150 comboBox.setModel(new DefaultComboBoxModel(new String[] {"u590Du5229u8BA1u7B97", "u5355u5229u8BA1u7B97", "u5B58u94B1u4F30u7B97"}));
151 comboBox.setBounds(10, 10, 90, 21);
152 contentPane.add(comboBox);
153 }


}

原文地址:https://www.cnblogs.com/LwF39/p/5274335.html