-
Notifications
You must be signed in to change notification settings - Fork 0
/
除號器
102 lines (83 loc) · 2.58 KB
/
除號器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package gui;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame {
private JPanel contentPane;
private JLabel lblNewLabel;
private JTextField textDividend;
private JLabel label;
private JTextField tfDivisor;
private JButton btnNewButton;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrame frame = new MainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainFrame() {
setTitle("GUI");
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);
lblNewLabel = new JLabel("\u88AB\u9664\u6578");
lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
lblNewLabel.setBounds(40, 30, 71, 23);
contentPane.add(lblNewLabel);
textDividend = new JTextField();
textDividend.setBounds(130, 27, 136, 29);
contentPane.add(textDividend);
textDividend.setColumns(10);
label = new JLabel("\u9664\u6578");
label.setHorizontalAlignment(SwingConstants.RIGHT);
label.setBounds(40, 74, 71, 23);
contentPane.add(label);
tfDivisor = new JTextField();
tfDivisor.setColumns(10);
tfDivisor.setBounds(130, 71, 136, 29);
contentPane.add(tfDivisor);
JScrollPane taResult = new JScrollPane();
taResult.setBounds(40, 115, 253, 108);
contentPane.add(taResult);
JTextArea toArea = new JTextArea();
taResult.setViewportView(toArea);
btnNewButton = new JButton("\u9664\u6CD5\u904B\u7B97");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int dividend=Integer.parseInt(textDividend.getText());
int divisor=Integer.parseInt(tfDivisor.getText());
int quotient=dividend/divisor;
int remainder=dividend % divisor;
String text=String.format("%d / %d = %d....%d",dividend,divisor,quotient,remainder);
toArea.setText(text);
}
});
btnNewButton.setBounds(302, 74, 111, 31);
contentPane.add(btnNewButton);
}
}