-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculateWindow.java
More file actions
43 lines (41 loc) · 1.13 KB
/
CalculateWindow.java
File metadata and controls
43 lines (41 loc) · 1.13 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
import java.awt.*;
import javax.swing.*;
public class CalculateWindow extends JFrame{
JTextField lengthInput,weightInput;
JComboBox<String>choiceUnit;
JTextArea outputResult;
JButton button;
UnitListener unitL;
ComputerListener computerL;
CalculateWindow(){
init();
setBounds(100,100,390,360);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init() {
setLayout(new FlowLayout());
lengthInput=new JTextField(5);
weightInput=new JTextField(5);
choiceUnit=new JComboBox<String>();
button=new JButton("计算");
choiceUnit.addItem("选择体重单位");
choiceUnit.addItem("厘米/斤");
choiceUnit.addItem("米/公斤");
outputResult=new JTextArea(9,30);
unitL=new UnitListener();
computerL=new ComputerListener();
unitL.setChoiceUnit(choiceUnit);
unitL.setComputerL(computerL);
computerL.setLength(lengthInput);
computerL.setWeightInput(weightInput);
computerL.setOutputResult(outputResult);
choiceUnit.addItemListener(unitL);
button.addActionListener(computerL);
add(lengthInput);
add(choiceUnit);
add(weightInput);
add(button);
add(new JScrollPane(outputResult));
}
}