-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddStudentInfoFrame.java
More file actions
108 lines (100 loc) · 2.89 KB
/
addStudentInfoFrame.java
File metadata and controls
108 lines (100 loc) · 2.89 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
102
103
104
105
106
107
108
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import Member.Administrator;
public class addStudentInfoFrame implements ActionListener {
Administrator user;
JFrame f;
//宣告輸入欄
JTextField Id = new JTextField(9);
JTextField Name = new JTextField(20);
JTextField InYear = new JTextField(10);
public addStudentInfoFrame(Administrator user) {
this.user = user;
//設定框架
f = new JFrame("新增學生資訊");
f.setSize(900, 600);
f.setLocationRelativeTo(null);//視窗置中
f.setResizable(false);//視窗放大按鈕無效
Container cp = f.getContentPane();
cp.setLayout(null);
//建立標籤
//標籤 學號
JLabel lb = new JLabel("學號:");
lb.setLocation(287,140);
lb.setSize(120,47);
lb.setFont(new Font("微軟正黑體", Font.BOLD, 30));
cp.add(lb);
//標籤 姓名
lb = new JLabel("姓名:");
lb.setLocation(287,200);
lb.setSize(120,47);
lb.setFont(new Font("微軟正黑體", Font.BOLD, 30));
cp.add(lb);
//標籤 入學年分
lb = new JLabel("入學年分:");
lb.setLocation(228,260);
lb.setSize(156,47);
lb.setFont(new Font("微軟正黑體", Font.BOLD,30));
cp.add(lb);
//建立輸入欄
//輸入欄 Id
Id.setLocation(380,149);
Id.setSize(220,35);
Id.setFont(new Font("微軟正黑體", Font.BOLD, 20));
cp.add(Id);
//輸入欄 Name
Name.setLocation(380,209);
Name.setSize(220,35);
Name.setFont(new Font("微軟正黑體", Font.BOLD, 20));
cp.add(Name);
//輸入欄 InYear
InYear.setLocation(380,269);
InYear.setSize(220,35);
InYear.setFont(new Font("微軟正黑體", Font.BOLD, 20));
cp.add(InYear);
//建立按鈕
JButton add = new JButton("新增");
JButton reset = new JButton("重置");
//按鈕 新增
add.setLocation(297,330);
add.setSize(120,47);
add.setFont(new Font("微軟正黑體",Font.BOLD,28));
add.addActionListener(this);
cp.add(add);
//按鈕 重置
reset.setLocation(443,330);
reset.setSize(120,47);
reset.setFont(new Font("微軟正黑體",Font.BOLD,28));
reset.addActionListener(this);
cp.add(reset);
//啟動
f.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
String id = Id.getText();
String name = Name.getText();
String inYear = InYear.getText();
if(cmd.equals("新增")) {
if(id.equals("") || name.equals("") || inYear.equals("")){
JOptionPane.showMessageDialog(null, "欄位不可為空");
}
else if(id.length() != 9){
JOptionPane.showMessageDialog(null, "學號須為九位數");
}
else {
user.addStudentInfo(id, name, inYear);
Id.setText("");
Name.setText("");
InYear.setText("");
}
}
if(cmd.equals("重置")) {
Id.setText("");
Name.setText("");
InYear.setText("");
}
}
}