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