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
18 public class FuLiJiSuanQi extends JFrame {
19
20 /**
21 *
22 */
23 private static final long serialVersionUID = 1L;
24 private JPanel contentPane;
25 private JTextField textField_1;
26 private JTextField textField_2;
27 private JTextField textField;
28 private JTextField textField_3;
29 private JLabel label_1;
30 /**
31 * Launch the application.
32 */
33 public static void main(String[] args) {
34 EventQueue.invokeLater(new Runnable() {
35 public void run() {
36 try {
37 FuLiJiSuanQi frame = new FuLiJiSuanQi();
38 frame.setVisible(true);
39 } catch (Exception e) {
40 e.printStackTrace();
41 }
42 }
43 });
44 }
45
46 /**
47 * Create the frame.
48 */
49 public FuLiJiSuanQi() {
50 setTitle("\u590D\u5229\u8BA1\u7B97\u5668");
51 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
52 setBounds(100, 100, 450, 300);
53 contentPane = new JPanel();
54 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
55 setContentPane(contentPane);
56 contentPane.setLayout(null);
57
58 JLabel label = new JLabel("\u5B58\u6B3E\uFF08\u4E07\uFF09:");
59 label.setFont(new Font("宋体", Font.PLAIN, 16));
60 label.setBounds(5, 22, 90, 15);
61 contentPane.add(label);
62
63 textField = new JTextField();
64 textField.setBounds(105, 20, 130, 21);
65 contentPane.add(textField);
66 textField.setColumns(10);
67 //x=textField.getText();
68
69 label_1 = new JLabel("\u5229\u7387( %):");
70 label_1.setFont(new Font("宋体", Font.PLAIN, 16));
71 label_1.setBounds(5, 75, 81, 15);
72 contentPane.add(label_1);
73
74 textField_1 = new JTextField();
75 textField_1.setBounds(105, 45, 130, 21);
76 contentPane.add(textField_1);
77 textField_1.setColumns(10);
78
79 JLabel label_2 = new JLabel("\u5E74\u9650(\u5E74):");
80 label_2.setFont(new Font("宋体", Font.PLAIN, 16));
81 label_2.setBounds(5, 47, 104, 15);
82 contentPane.add(label_2);
83
84 textField_2 = new JTextField();
85 textField_2.setBounds(105, 73, 130, 21);
86 contentPane.add(textField_2);
87 textField_2.setColumns(10);
88
89 JButton btnNewButton = new JButton("\u5229\u606F");
90 btnNewButton.addMouseListener(new MouseAdapter() {
91 @Override
92 public void mouseClicked(MouseEvent e) {
93 double capital=Double.parseDouble(textField.getText());
94 double year=Double.parseDouble(textField_1.getText());
95 double rate=Double.parseDouble(textField_2.getText());
96 double sum=capital*Math.pow((1+rate/100),year);
97 textField_3.setText(Double.toString(sum));
98 }
99 });
100 btnNewButton.addActionListener(new ActionListener() {
101 public void actionPerformed(ActionEvent e) {
102 }
103 });
104 btnNewButton.setBounds(5, 120, 69, 23);
105 contentPane.add(btnNewButton);
106
107 textField_3 = new JTextField();
108 textField_3.setForeground(new Color(127, 255, 212));
109 textField_3.setEnabled(false);
110 textField_3.setBounds(105, 121, 130, 21);
111 contentPane.add(textField_3);
112 textField_3.setColumns(10);
113 }
114 }
![]()