Skip to content

Commit b3cfe22

Browse files
author
shy-coder
committed
day19:初识swing
1 parent 286d5bc commit b3cfe22

File tree

3 files changed

+226
-0
lines changed

3 files changed

+226
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.shy.day19.StudentForm">
3+
<grid id="27dc6" binding="mainPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
4+
<constraints>
5+
<xy x="20" y="20" width="901" height="634"/>
6+
</constraints>
7+
<properties>
8+
<background color="-9016136"/>
9+
</properties>
10+
<border type="none"/>
11+
<children>
12+
<component id="a24ae" class="javax.swing.JButton" binding="button2" default-binding="true">
13+
<constraints border-constraint="South"/>
14+
<properties>
15+
<text value="Button"/>
16+
</properties>
17+
</component>
18+
<component id="cb42" class="javax.swing.JButton" binding="button4" default-binding="true">
19+
<constraints border-constraint="East"/>
20+
<properties>
21+
<text value="Button"/>
22+
</properties>
23+
</component>
24+
<grid id="7ee95" binding="centerPanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
25+
<constraints border-constraint="Center"/>
26+
<properties/>
27+
<border type="none"/>
28+
<children>
29+
<component id="afb62" class="javax.swing.JLabel" binding="resultLabel">
30+
<constraints/>
31+
<properties>
32+
<font size="20" style="1"/>
33+
<text value="体检结果:"/>
34+
</properties>
35+
</component>
36+
</children>
37+
</grid>
38+
<grid id="ad422" binding="topPanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
39+
<constraints border-constraint="North"/>
40+
<properties>
41+
<background color="-5615473"/>
42+
<foreground color="-5615486"/>
43+
<preferredSize width="0" height="50"/>
44+
</properties>
45+
<border type="none"/>
46+
<children>
47+
<component id="e6edc" class="javax.swing.JButton" binding="button1" default-binding="true">
48+
<constraints/>
49+
<properties>
50+
<text value="Button"/>
51+
</properties>
52+
</component>
53+
<component id="44b8b" class="javax.swing.JButton" binding="button5" default-binding="true">
54+
<constraints/>
55+
<properties>
56+
<text value="Button"/>
57+
</properties>
58+
</component>
59+
<component id="aa209" class="javax.swing.JButton" binding="button6" default-binding="true">
60+
<constraints/>
61+
<properties>
62+
<text value="Button"/>
63+
</properties>
64+
</component>
65+
<component id="64fc" class="javax.swing.JButton" binding="button7" default-binding="true">
66+
<constraints/>
67+
<properties>
68+
<text value="Button"/>
69+
</properties>
70+
</component>
71+
<component id="e73f" class="javax.swing.JButton" binding="button8" default-binding="true">
72+
<constraints/>
73+
<properties>
74+
<text value="Button"/>
75+
</properties>
76+
</component>
77+
<component id="1cec4" class="javax.swing.JButton" binding="button9" default-binding="true">
78+
<constraints/>
79+
<properties>
80+
<text value="Button"/>
81+
</properties>
82+
</component>
83+
</children>
84+
</grid>
85+
<grid id="a0774" binding="leftPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
86+
<margin top="0" left="0" bottom="0" right="0"/>
87+
<constraints border-constraint="West"/>
88+
<properties>
89+
<background color="-3962253"/>
90+
<doubleBuffered value="false"/>
91+
<minimumSize width="40" height="10"/>
92+
<preferredSize width="200" height="10"/>
93+
</properties>
94+
<border type="bevel-raised" title="titile"/>
95+
<children>
96+
<component id="abc17" class="javax.swing.JTextField" binding="nameField">
97+
<constraints>
98+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="2" fill="1" indent="0" use-parent-layout="false">
99+
<preferred-size width="150" height="-1"/>
100+
</grid>
101+
</constraints>
102+
<properties/>
103+
</component>
104+
<component id="5e545" class="javax.swing.JTextField" binding="weightField">
105+
<constraints>
106+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false">
107+
<preferred-size width="150" height="-1"/>
108+
</grid>
109+
</constraints>
110+
<properties/>
111+
</component>
112+
<component id="43684" class="javax.swing.JButton" binding="检查Button" default-binding="true">
113+
<constraints>
114+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
115+
</constraints>
116+
<properties>
117+
<text value="检查"/>
118+
</properties>
119+
</component>
120+
</children>
121+
</grid>
122+
</children>
123+
</grid>
124+
</form>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.shy.day19;
2+
3+
import javax.swing.*;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.ActionListener;
6+
7+
/**
8+
* @ClassName StudentForm
9+
* @Author shy
10+
* @Date 2020/11/7
11+
**/
12+
public class StudentForm {
13+
private JPanel mainPanel;
14+
private JButton button2;
15+
private JButton button4;
16+
private JPanel centerPanel;
17+
private JPanel topPanel;
18+
private JButton button1;
19+
private JButton button5;
20+
private JButton button6;
21+
private JButton button7;
22+
private JButton button8;
23+
private JButton button9;
24+
private JPanel leftPanel;
25+
private JTextField nameField;
26+
private JTextField weightField;
27+
private JButton 检查Button;
28+
private JLabel resultLabel;
29+
30+
public StudentForm() {
31+
检查Button.addActionListener(e -> {
32+
//点击按钮需要做的逻辑
33+
System.out.println("click");
34+
String name = nameField.getText();
35+
int weight = Integer.parseInt(weightField.getText());
36+
student student = new student(name,weight);
37+
if (weight > 100){
38+
//JOptionPane.showMessageDialog(null,"体检不通过");
39+
resultLabel.setText(student.getName()+"体检未通过");
40+
}else {
41+
//JOptionPane.showMessageDialog(null,"体检通过");
42+
resultLabel.setText(student.getName()+"体检通过");
43+
}
44+
nameField.setText("");
45+
weightField.setText("");
46+
});
47+
}
48+
49+
public static void main(String[] args) {
50+
JFrame frame = new JFrame("StudentForm");
51+
frame.setContentPane(new StudentForm().mainPanel);
52+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
53+
//frame.pack();
54+
frame.setSize(1200,900);
55+
frame.setLocationRelativeTo(null);
56+
frame.setVisible(true);
57+
}
58+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.shy.day19;
2+
3+
/**
4+
* @ClassName student
5+
* @Author shy
6+
* @Date 2020/11/7
7+
**/
8+
public class student {
9+
10+
private String name;
11+
private Integer weight;
12+
13+
public student() {
14+
}
15+
16+
public student(String name, Integer weight) {
17+
this.name = name;
18+
this.weight = weight;
19+
}
20+
21+
public String getName() {
22+
return name;
23+
}
24+
25+
public void setName(String name) {
26+
this.name = name;
27+
}
28+
29+
public Integer getWeight() {
30+
return weight;
31+
}
32+
33+
public void setWeight(Integer weight) {
34+
this.weight = weight;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return "student{" +
40+
"name='" + name + '\'' +
41+
", weight=" + weight +
42+
'}';
43+
}
44+
}

0 commit comments

Comments
 (0)