学生成绩管理系统 (1)

系统介绍

以上是系统大致功能的介绍
MYSQL版本为8.2.0
MYSQL + JAVA + SWING 编程实现的一个学生成绩管理系统
软件MYSQL eclipse Navicat

学生成绩管理系统

坑点
eclipse新版MYSQL方式得变化
eclipse与MYSQL之间的编码格式得一致
https://blog.csdn.net/weixin_44193041/article/details/106575698
连接

新版MYSQL相对于旧版部分语句失效
所以使用MYSQL语句时得考虑新版
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggre…
问题如何解决
打开mysql输入以下语句即可解决
mysql> SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,’ONLY_FULL_GROUP_BY’,’’));
以上不行的话在navicat里面输入
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,’ONLY_FULL_GROUP_BY’,’’));

具体原因
MySQL 5.7.5及以上功能依赖检测功能。如果启用了ONLY_FULL_GROUP_BY SQL模式(默认情况下),MySQL将拒绝选择列表,HAVING条件或ORDER BY列表的查询引用在GROUP BY子句中既未命名的非集合列,也不在功能上依赖于它们。(5.7.5之前,MySQL没有检测到功能依赖关系,默认情况下不启用ONLY_FULL_GROUP_BY。有关5.7.5之前的行为的说明,请参见“MySQL 5.6参考手册”。)

该程序的数据库语句,详解
https://blog.csdn.net/weixin_44193041/article/details/106576178
数据库

系统管理模块

系统管理模块实现了
管理员的登陆
用户信息

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
package studentsystem.bean;


// 一个用户类,包括用户名,密码,以及用户是否登陆添加其构造器
public class User {
private String username; //用户名
private String password; //密码
private int isLogin = 0; //用户是否登陆

public int getIsLogin() {
return isLogin;
}
public void setIsLogin(int isLogin) {
this.isLogin = isLogin;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

}

用户登陆代码

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package studentsystem.frame;

import studentsystem.bean.User;
import studentsystem.dao.ManageHelper;
import studentsystem.util.WindowUtil;

import java.awt.Color;
import java.awt.Container;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
//登陆界面
public class StudentSystemLoginFrame extends JFrame{

private JLabel username_Label; //用户名标签。
private JLabel password_Label; //密码标签。
private JTextField username_Text; //用户名文本域。
private JPasswordField password_Text; //密码文本域。
private JButton login_Button; //登陆按钮。
private JButton register_Button; //注册按钮。
private JFrame jf; //当前窗口 。
public StudentSystemLoginFrame(){
super("学生成绩管理系统登录界面");
this.jf = this;
this.setLayout(null);//设置为空布局。
this.setSize(400,300);//设置大小。
Container c = this.getContentPane();
c.setBackground(Color.WHITE);//设置背景颜色。
username_Label = new JLabel("用户名:"); //创建"用户名"标签。
username_Label.setBounds(100, 60, 50, 20); //设置"用户名"标签位置。
c.add(username_Label); //添加"用户名"标签。

username_Text = new JTextField(); //创建"用户名"文本域。
username_Text.setBounds(160, 60, 120, 20); //设置"用户名"文本域位置。
username_Text.grabFocus();//获得光标。
c.add(username_Text); //添加"用户名"文本域。

password_Label = new JLabel("密码:"); //创建"密码"标签。
password_Label.setBounds(100, 140, 50, 20);
c.add(password_Label); //添加"密码"标签。

password_Text = new JPasswordField(); //创建"密码"文本域。
password_Text.setBounds(160, 140, 120, 20); //设置"密码"文本域位置。
c.add(password_Text); //添加"密码"文本域。

login_Button = new JButton("登录"); //创建"登录"按钮。
login_Button.setBounds(100, 210, 60, 20); //设置"登录"按钮位置。
//注册"登录"按钮事件监听。
login_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
String username = username_Text.getText().trim();
String password = new String(password_Text.getPassword());
if(username.equals("")){
JOptionPane.showMessageDialog(jf, "用户名不能为空","",JOptionPane.WARNING_MESSAGE);
return ;
}
if(password.equals("")){
JOptionPane.showMessageDialog(jf, "密码不能为空","",JOptionPane.WARNING_MESSAGE);
return ;
}
//登录业务处理。
User user = new User();//创建用户对象
user.setUsername(username);
user.setPassword(password);
ManageHelper helper = new ManageHelper();//创建数据库业务处理对象
if(helper.Login(user)){ //登陆业务处理
if(helper.Check_IsLogin(user)){
JOptionPane.showMessageDialog(jf, "重复登陆!","",JOptionPane.WARNING_MESSAGE);
return ;
}else{
JOptionPane.showMessageDialog(jf, "登陆成功!");
jf.dispose();//关闭当前窗口。
//修改登陆情况
user.setIsLogin(1);//修改成为已经登陆。
helper.Update_IsLogin(user);
//打开主界面
user.setPassword("");//重置密码
StudentSystemMainFrame frame = new StudentSystemMainFrame(user);
return ;
}
}else{
JOptionPane.showMessageDialog(jf, "用户名或密码错误!");
Reset(); //重置
return ;
}

}
});
c.add(login_Button); //添加"登录"按钮 。


register_Button = new JButton("注册"); //创建"注册"按钮。
register_Button.setBounds(250, 210, 60, 20); //设置"注册"按钮位置。
//注册"注册"按钮事件监听。
register_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
jf.dispose(); //当前窗口关闭。
StudentSystemRegisterFrame studentSystemRegisterFrame = new StudentSystemRegisterFrame(); //打开注册界面

}
});
c.add(register_Button); //添加"注册"按钮。

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false); //设置大小不可改变。
WindowUtil.setFrameCenter(this);//设置窗口居中。
try {
Image img = ImageIO.read(this.getClass().getResource("/2.png"));
this.setIconImage(img);

} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

this.setVisible(true); //设置窗体可见。
}

//重置
public void Reset(){
username_Text.setText("");
password_Text.setText("");
}
}

登陆窗口
登陆成功
管理员的注册
管理员注册代码

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package studentsystem.frame;

import studentsystem.bean.User;
import studentsystem.dao.ManageHelper;
import studentsystem.util.WindowUtil;

import java.awt.Color;
import java.awt.Container;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
//注册界面

public class StudentSystemRegisterFrame extends JFrame {

private JLabel username_Label; //用户名标签。
private JLabel password_Label; //密码标签。
private JLabel repassword_Label; //确认密码标签。
private JTextField username_Text; //用户名文本域。
private JPasswordField password_Text; //密码文本域。
private JPasswordField repassword_Text; //确认密码文本域。
private JButton register_Button; //注册按钮。
private JButton cancel_Button; //取消按钮。
private JFrame jf; //当前窗口 。

public StudentSystemRegisterFrame(){
super("学生成绩管理系统注册界面");
this.jf = this;
this.setLayout(null);//设置为空布局。
this.setSize(400,300);//设置大小。
Container c = this.getContentPane();
c.setBackground(Color.WHITE);//设置背景颜色。
username_Label = new JLabel("用户名:"); //创建"用户名"标签。
username_Label.setBounds(100, 60, 50, 20); //设置"用户名"标签位置。
c.add(username_Label); //添加"用户名"标签。

username_Text = new JTextField(); //创建"用户名"文本域。
username_Text.setBounds(160, 60, 120, 20); //设置"用户名"文本域位置。
username_Text.grabFocus();//获得光标。
c.add(username_Text); //添加"用户名"文本域。

password_Label = new JLabel("密码:"); //创建"密码"标签。
password_Label.setBounds(100, 110, 50, 20);
c.add(password_Label); //添加"密码"标签。

password_Text = new JPasswordField(); //创建"密码"文本域。
password_Text.setBounds(160, 110, 120, 20); //设置"密码"文本域位置。
c.add(password_Text); //添加"密码"文本域。

repassword_Label = new JLabel("确认密码"); //创建"确认密码"标签。
repassword_Label.setBounds(100, 162, 70, 20); //设置"确认密码"标签位置。
c.add(repassword_Label); //添加"确认密码"标签。

repassword_Text = new JPasswordField(); //创建"确认密码"文本域。
repassword_Text.setBounds(160, 162, 120, 20); //设置"确认密码"文本域位置。
c.add(repassword_Text); //添加"确认密码"文本域。

register_Button = new JButton("注册"); //创建"注册"按钮。
register_Button.setBounds(90, 210, 60, 20); //设置"注册"按钮位置。
//注册"注册"按钮事件监听。
register_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
String username = username_Text.getText().trim();//获得用户名。
String password = new String(password_Text.getPassword()); //获得密码。
String repassword = new String(repassword_Text.getPassword()); //获得确认密码。
if(username.equals("")){
JOptionPane.showMessageDialog(jf, "用户名不能为空!","",JOptionPane.WARNING_MESSAGE);
return ;
}
if(password.equals("")){
JOptionPane.showMessageDialog(jf, "密码不能为空!","",JOptionPane.WARNING_MESSAGE);
return ;
}
if(repassword.equals("")){
JOptionPane.showMessageDialog(jf, "确认密码不能为空!","",JOptionPane.WARNING_MESSAGE);
return ;
}
if(!password.equals(repassword)){
JOptionPane.showMessageDialog(jf, "两次密码不一致!","",JOptionPane.WARNING_MESSAGE);
return ;
}
//注册业务处理。
User user = new User();//创建用户对象
user.setUsername(username);
user.setPassword(password);
ManageHelper helper = new ManageHelper();//创建数据库业务处理对象
if(helper.Register(user)){//注册处理
JOptionPane.showMessageDialog(jf, "注册成功!");
jf.dispose();//关闭当前窗口
StudentSystemLoginFrame frame = new StudentSystemLoginFrame();//返回登陆页面。
return ;
}else{
JOptionPane.showMessageDialog(jf, "注册失败!");
Reset(); //重置
return ;
}

}
});
c.add(register_Button); //添加"注册"按钮。


cancel_Button = new JButton("取消"); //创建"取消"按钮。
cancel_Button.setBounds(250, 210, 60, 20); //设置"取消"按钮位置。
//注册"取消"按钮事件监听。
cancel_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
jf.dispose();//关闭当前页面。
StudentSystemLoginFrame studentSystemLoginFrame = new StudentSystemLoginFrame();//打开登陆页面。
}
});
c.add(cancel_Button); //添加"取消"按钮。

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false); //设置大小不可改变。
WindowUtil.setFrameCenter(this);//设置窗口居中。
try {
Image img = ImageIO.read(this.getClass().getResource("/2.png"));
this.setIconImage(img);

} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
this.setVisible(true); //设置窗体可见。
}

//重置
public void Reset(){
username_Text.setText("");
password_Text.setText("");
repassword_Text.setText("");
}
}

注册界面
管理员的登陆状态判断
防止其他人再次重复登陆
修改管理员密码
修改密码代码

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package studentsystem.frame;

import studentsystem.bean.User;
import studentsystem.dao.ManageHelper;
import studentsystem.util.WindowUtil;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

//修改密码界面
public class UpdatePasswordFrame extends JDialog{

private JLabel password_Label; //原密码标签。
private JLabel newpassword_Label; //新密码标签。
private JLabel repassword_Label; //确认密码标签。
private JPasswordField password_Text; //原密码文本域。
private JPasswordField newpassword_Text; //新密码文本域。
private JPasswordField repassword_Text; //确认密码文本域。
private JButton confirm_Button; //确认按钮。
private JButton cancel_Button; //取消按钮。
private JDialog jd; //当前窗口 。
private User user;
/**
*
* @param owner 它的父窗口
* @param title 窗口名
* @param modal 指定的模式窗口,还有非模式窗口
*/
public UpdatePasswordFrame(JFrame owner, String title, boolean modal,User user){
super(owner, title, modal);
this.user = user;
this.jd = this;
this.setLayout(null);//设置为空布局。
this.setSize(400,300);//设置大小。
Container c = this.getContentPane();
c.setBackground(Color.WHITE);//设置背景颜色。
password_Label = new JLabel("原密码:"); //创建"原密码"标签。
password_Label.setBounds(100, 60, 50, 20); //设置"原密码"标签位置。
c.add(password_Label); //添加"密码"标签。

password_Text = new JPasswordField(); //创建"原密码"文本域。
password_Text.setBounds(160, 60, 120, 20); //设置"原密码"文本域位置。
password_Text.grabFocus();//获得光标。
c.add(password_Text); //添加"密码"文本域。

newpassword_Label = new JLabel("新密码:"); //创建"新密码"标签。
newpassword_Label.setBounds(100, 110, 50, 20);
c.add(newpassword_Label); //添加"新密码"标签。

newpassword_Text = new JPasswordField(); //创建"新密码"文本域。
newpassword_Text.setBounds(160, 110, 120, 20); //设置"新密码"文本域位置。
c.add(newpassword_Text); //添加"新密码"文本域。

repassword_Label = new JLabel("确认密码"); //创建"确认密码"标签。
repassword_Label.setBounds(100, 162, 70, 20); //设置"确认密码"标签位置。
c.add(repassword_Label); //添加"确认密码"标签。

repassword_Text = new JPasswordField(); //创建"确认密码"文本域。
repassword_Text.setBounds(160, 162, 120, 20); //设置"确认密码"文本域位置。
c.add(repassword_Text); //添加"确认密码"文本域。

confirm_Button = new JButton("确认"); //创建"确认"按钮。
confirm_Button.setBounds(90, 210, 60, 20); //设置"确认"按钮位置。
//注册"确认"按钮事件监听。
confirm_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
String password = new String(password_Text.getPassword());
String repassword = new String(repassword_Text.getPassword());
String newpassword = new String(newpassword_Text.getPassword());
if(password.equals("")){
JOptionPane.showMessageDialog(jd, "原密码不能为空!","",JOptionPane.WARNING_MESSAGE);
return ;
}
if(newpassword.equals("")){
JOptionPane.showMessageDialog(jd, "新密码不能为空!","",JOptionPane.WARNING_MESSAGE);
return ;
}
if(repassword.equals("")){
JOptionPane.showMessageDialog(jd, "确认密码不能为空!","",JOptionPane.WARNING_MESSAGE);
return ;
}
if(repassword.equals(newpassword)){
//检查原密码是否正确
ManageHelper helper = new ManageHelper();
user.setPassword(password);
if(helper.Login(user)){//检查原密码是否正确
helper.update_Password(user, newpassword); //修改密码
JOptionPane.showMessageDialog(jd, "修改密码成功!");
jd.dispose();//关闭当前窗口
return ;
}else{
JOptionPane.showMessageDialog(jd,"原密码不正确!","",JOptionPane.WARNING_MESSAGE);
Reset(); //重置
return ;
}
}else{
JOptionPane.showMessageDialog(jd,"两次密码不一致","",JOptionPane.WARNING_MESSAGE);
Reset(); //重置
return ;
}

}
});
c.add(confirm_Button); //添加"确认"按钮。


cancel_Button = new JButton("取消"); //创建"取消"按钮。
cancel_Button.setBounds(250, 210, 60, 20); //设置"取消"按钮位置。
//注册"取消"按钮事件监听。
cancel_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
jd.dispose();//关闭当前页面。

}
});
c.add(cancel_Button); //添加"取消"按钮。


this.setResizable(false); //设置大小不可改变。
WindowUtil.setFrameCenter(this);//设置窗口居中。
this.setVisible(true); //设置窗体可见。
}

//重置
public void Reset(){
password_Text.setText("");
repassword_Text.setText("");
newpassword_Text.setText("");
}
}

修改密码
和退出登陆
退出登陆在主界面中退出即可
退出登陆界面

教师管理模块

学生管理
添加学生信息
在这里插入图片描述
添加学生信息代码

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package studentsystem.frame;

import studentsystem.bean.Student;
import studentsystem.dao.ManageHelper;
import studentsystem.util.Tools;
import studentsystem.util.WindowUtil;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
//添加学生界面
public class AddStudentFrame extends JDialog{
private JButton add_Button; //"添加"按钮。
private JButton cancel_Button; //"取消"按钮。
private JComboBox sex_Box; //"性别"选项。
private JComboBox major_Box; //"专业"选项。
private JComboBox department_Box; //"所属院系"选项。
private JLabel student_ID; //"学号"标签。
private JLabel student_Name; //"姓名"标签。
private JLabel sex_Label; //"性别"标签。
private JLabel classe_Label; //"班级"标签。
private JLabel grade_Label; //"年级标签"。
private JLabel major_Label; //"专业"标签。
private JLabel department_Label; //"所属院系"标签。
private JTextField student_IDText; //"学号"文本域。
private JTextField student_NameText; //"姓名"文本域。
private JComboBox classe_Box; //"班级"文本域。
private JComboBox grade_Box; //"年级"文本域。
private JDialog jd; //当前窗口。
private HashMap<String, String> departments; //所有院系集合
private HashMap<String, String> all_Major; //所有专业集合
private Vector<String> majors; //专业名称集合
private ManageHelper helper; //数据库业务处理对象
private Vector<String> classes; //班级集合
/**
*
* @param owner 它的父窗口
* @param title 窗口名
* @param modal 指定的模式窗口,还有非模式窗口
*/
public AddStudentFrame(JFrame owner, String title, boolean modal){
super(owner, title, modal);
helper = new ManageHelper(); //创建数据库业务处理对象

departments = this.helper.getAllDepartment(); //获得所有院系
all_Major = this.helper.getAllMajor(); //获得所有的专业
this.jd = this;
this.setSize(350,429); //设置窗体大小。
this.setLayout(null); //设置空布局。

student_ID = new JLabel("班号:");
student_ID.setBounds(78, 48, 30, 20);
this.add(student_ID);

student_IDText = new JTextField();
student_IDText.setBounds(116, 48, 150, 20);
this.add(student_IDText);

student_Name = new JLabel("姓名:");
student_Name.setBounds(78, 88, 30, 20);
this.add(student_Name);


student_NameText = new JTextField();
student_NameText.setBounds(116, 88, 150, 20);
this.add(student_NameText);

sex_Label = new JLabel("性别:");
sex_Label.setBounds(78, 128, 30, 20);
this.add(sex_Label);

sex_Box = new JComboBox(new String[]{"","男","女"});
sex_Box.setBounds(116, 128, 60, 20);
this.add(sex_Box);



grade_Label = new JLabel("年级:");
grade_Label.setBounds(78, 168, 30, 20);
this.add(grade_Label);

grade_Box = new JComboBox<String>(Tools.CreateGrade()); //需要获得获得年级选项
grade_Box.setBounds(116, 168, 150, 20);
//注册"年级选项"事件监听
grade_Box.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
classe_Box.removeAllItems();//移除"班级选项"的内容
String option = major_Box.getSelectedItem().toString();
String major_id = all_Major.get(option); //专业编号
String grade = grade_Box.getSelectedItem().toString();
if(!grade.equals("")){
classes = helper.getAllClasse(grade,major_id); //获得班级
for(String s : classes){
classe_Box.addItem(s);
}
}
}
});
this.add(grade_Box);


department_Label = new JLabel("院系:");
department_Label.setBounds(78, 208, 30, 20);

this.add(department_Label);

department_Box = new JComboBox(departments.keySet().toArray());//获得键的集合
//注册"院系"选项事件监听
department_Box.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
major_Box.removeAllItems();//移除"专业选项"的内容
String option = department_Box.getSelectedItem().toString();//获得选项名称
String department_ID = departments.get(option); //获得院系编号
if(!department_ID.equals("")){
majors = helper.getMajor(department_ID); //获得专业
for(String s : majors){
major_Box.addItem(s);
}
}

}
});
department_Box.setBounds(116, 208, 150, 20);
this.add(department_Box);

major_Label = new JLabel("专业:");
major_Label.setBounds(78, 248, 30, 20);
this.add(major_Label);

major_Box = new JComboBox(new String[]{""});//防止空指针异常
//注册"专业"选项事件监听
major_Box.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(major_Box.getSelectedItem()!=null){ //防止空指针
if(!major_Box.getSelectedItem().toString().equals("")){
if(major_Box.getSelectedItem().toString().equals("") || grade_Box.getSelectedItem()==null || grade_Box.getSelectedItem().toString().equals("")){
JOptionPane.showMessageDialog(jd, "年级不能为空", "", JOptionPane.WARNING_MESSAGE);
major_Box.setSelectedIndex(0); //设置为空选项
return ;
}
classe_Box.removeAllItems();//移除"班级选项"的内容
String option = major_Box.getSelectedItem().toString();
String major_id = all_Major.get(option); //专业编号
String grade = grade_Box.getSelectedItem().toString();
if(!grade.equals("")){
classes = helper.getAllClasse(grade,major_id); //获得班级
for(String s : classes){
classe_Box.addItem(s);
}
}
}
}
}
});
major_Box.setBounds(116, 248, 150, 20);
this.add(major_Box);



classe_Label = new JLabel("班级:"); //需要获得班级选项
classe_Label.setBounds(78, 288, 30, 20);
this.add(classe_Label);

classe_Box = new JComboBox(new String[]{""});//防止空指针异常
classe_Box.setBounds(116, 288, 150, 20);
this.add(classe_Box);

add_Button = new JButton("添加");
add_Button.setBounds(70, 330, 60, 25);

//注册"确认"按钮事件监听
add_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
Student student = new Student();
String sid = student_IDText.getText().trim();
String name = student_NameText.getText().trim();
String sex = sex_Box.getSelectedItem().toString();
String classe = classe_Box.getSelectedItem().toString();
String grade = grade_Box.getSelectedItem().toString();
String department_ID = null;
String major_ID = null;
String department_Name = null;
String major_Name = null;
//数据校验部分
if(sid.equals("")){
JOptionPane.showMessageDialog(jd, "班号不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}
if(sid.length()!=2){
JOptionPane.showMessageDialog(jd, "班号必须是两位数!", "", JOptionPane.WARNING_MESSAGE);
student_IDText.setText("");
return ;
}
if(name.equals("")){
JOptionPane.showMessageDialog(jd, "姓名不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}
if(sex.equals("")){
JOptionPane.showMessageDialog(jd, "性别不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}
if(grade.equals("")){
JOptionPane.showMessageDialog(jd, "年级不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}
if(classe.equals("")){
JOptionPane.showMessageDialog(jd, "班级不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}
if(department_Box.getSelectedItem()==null){ //先检查再用
JOptionPane.showMessageDialog(jd, "院系不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}else{
department_Name = department_Box.getSelectedItem().toString(); //获得院系名称
department_ID = departments.get(department_Name); //获得院系编号
}
if(department_ID.equals("")){
JOptionPane.showMessageDialog(jd, "院系不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}
if(major_Box.getSelectedItem()==null){ //先检查再用
JOptionPane.showMessageDialog(jd, "专业不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}else{
major_Name = major_Box.getSelectedItem().toString();//获得专业名称
major_ID = all_Major.get(major_Name); //获得专业编号
}
if(major_ID.equals("")){
JOptionPane.showMessageDialog(jd, "专业不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}
String id = Tools.CreateID(grade, classe, major_ID, department_ID, sid);//生成学号
student_ID.setText("学号:");
student_IDText.setText(id); //设置学号文本域
JOptionPane.showMessageDialog(jd, "该学生的id为:"+id);
student.setStudent_ID(id);
student.setStudent_Name(name);
student.setSex(sex);
student.setGrade(grade);
student.setClasse(classe);
student.setMajor_Name(major_Name);
student.setDepartment_Name(department_Name);
student.setMajor_ID(major_ID);
student.setDepartment_ID(department_ID);
if(helper.addStudent(student)){
JOptionPane.showMessageDialog(jd, "添加成功!");
jd.dispose(); //关闭当前窗口
return ;
}else{
JOptionPane.showMessageDialog(jd, "添加失败!", "", JOptionPane.WARNING_MESSAGE);
jd.dispose(); //关闭当前窗口
return ;
}


}
});
this.add(add_Button);

cancel_Button = new JButton("取消");
cancel_Button.setBounds(230, 330, 60, 25);
//注册"取消"按钮事件监听
cancel_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
jd.dispose();

}
});
this.add(cancel_Button);

WindowUtil.setFrameCenter(this);
this.setResizable(false);
this.setVisible(true);
}






}

查询学生信息
查询学生
查询学生信息代码

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package studentsystem.frame;

import studentsystem.model.StudentModel;
import studentsystem.util.CreateSql;
import studentsystem.util.WindowUtil;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
//查询学生信息界面
public class QueryStudentFrame extends JDialog{
private JPanel jp1,jp2,jp3; //面板。
private JLabel query_Label; //标签。
private JButton query_Button; //"查询"按钮。
private JComboBox query_List; //"查询"选项。
private JButton preciseQuery_Button; //"精确查询"按钮。
private JButton details_Button; //"详细信息"按钮。
private JTextField query_Text; //"查询"文本域。
private JTable jt; //表格。
private JScrollPane jsp; //滚动条。
private JDialog jd; //当前窗口。
private StudentModel studentModel;//学生数据模型类

private static Vector<String> query_Option;

static {
query_Option = new Vector<String>();
query_Option.add("全部");
query_Option.add("学号");
query_Option.add("姓名");
query_Option.add("性别");
query_Option.add("班级");
query_Option.add("年级");
query_Option.add("专业");
query_Option.add("院系");
}
/**
*
* @param owner 它的父窗口
* @param title 窗口名
* @param modal 指定的模式窗口,还有非模式窗口
*/
public QueryStudentFrame(JFrame owner, String title, boolean modal){
super(owner, title, modal);
this.jd = this;
Container c = this.getContentPane();

jp1 = new JPanel();
query_Label = new JLabel("请输入查询信息:");
jp1.add(query_Label);

query_Text = new JTextField(10);
jp1.add(query_Text);

query_List = new JComboBox<String>(query_Option);
jp1.add(query_List);

query_Button = new JButton("查询");
//注册"查询"按钮事件监听
query_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
String str = query_Text.getText().trim(); //查询内容
String option = query_List.getSelectedItem().toString(); //查询选项
String sql = CreateSql.getStudent_Sql(str, option); //获得sql语句
studentModel = new StudentModel(sql,jd);//构建新的数据模型类,并更新
jt.setModel(studentModel);//更新Jtable
}
});
jp1.add(query_Button);

preciseQuery_Button = new JButton("多条件查询");
//注册"多条件查询"按钮事件监听
preciseQuery_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
ConditionsQueryFrame frame = new ConditionsQueryFrame(jd, "多条件查询", true, jt);

}
});
jp1.add(preciseQuery_Button);
c.add(jp1,BorderLayout.NORTH); //添加面板

jp2 = new JPanel();
jt = new JTable();
String sql = CreateSql.getStudent_Sql(null, "全部");//查询全部内容
studentModel = new StudentModel(sql,jd);//构建新的数据模型类,并更新
jt.setModel(studentModel);



jsp = new JScrollPane(jt);
jp2.add(jsp);
c.add(jp2,BorderLayout.CENTER); //添加面板

jp3 = new JPanel();
details_Button = new JButton("详细信息");
//注册"详细信息"按钮事件监听
details_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
int rowNum = jt.getSelectedRow();
if(rowNum==-1){
JOptionPane.showMessageDialog(jd, "请选择一行!", "", JOptionPane.WARNING_MESSAGE);
return ;
}
DetailsFrame detailsFrame = new DetailsFrame(jd, "详细学生信息", true,rowNum,studentModel);
}
});
jp3.add(details_Button);
c.add(jp3,BorderLayout.SOUTH);

this.setSize(600,540);
this.setResizable(false);
WindowUtil.setFrameCenter(this);//设置窗体居中。
this.setVisible(true);

}
}

显示详细信息
显示详细信息代码

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package studentsystem.frame;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import studentsystem.model.StudentModel;
import studentsystem.util.WindowUtil;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

//详细信息界面
public class DetailsFrame extends JDialog{
private JButton confirm_Button; //"确认"按钮。
private JTextField sex_Text; //"性别"选项。
private JTextField major_Text; //"专业"选项。
private JTextField department_Text; //"所属院系"选项。
private JLabel student_ID; //"学号"标签。
private JLabel student_Name; //"姓名"标签。
private JLabel sex_Label; //"性别"标签。
private JLabel classe_Label; //"班级"标签。
private JLabel grade_Label; //"年级标签"。
private JLabel major_Label; //"专业"标签。
private JLabel department_Label; //"所属院系"标签。
private JTextField student_IDText; //"学号"文本域。
private JTextField student_NameText; //"姓名"文本域。
private JTextField classe_Text; //"班级"文本域。
private JTextField grade_Text; //"年级"文本域。
private StudentModel sm; //传入的学生数据模型
private JDialog jd; //当前窗口。
/**
*
* @param owner 它的父窗口
* @param title 窗口名
* @param modal 指定的模式窗口,还有非模式窗口
*/
public DetailsFrame(JDialog owner, String title, boolean modal, int rowNum,StudentModel sm){
super(owner, title, modal);
this.sm = sm; //传入学生数据模型
this.jd = this;
this.setSize(350,429); //设置窗体大小。
this.setLayout(null); //设置空布局。

student_ID = new JLabel("学号:");
student_ID.setBounds(78, 48, 30, 20);
this.add(student_ID);

student_IDText = new JTextField();
student_IDText.setEditable(false); //不可编辑
student_IDText.setText(sm.getValueAt(rowNum, 0).toString()); //获取学号并显示
student_IDText.setBounds(116, 48, 150, 20);
this.add(student_IDText);

student_Name = new JLabel("姓名:");
student_Name.setBounds(78, 88, 30, 20);
this.add(student_Name);


student_NameText = new JTextField();
student_NameText.setBounds(116, 88, 150, 20);
student_NameText.setEditable(false);//不可编辑
student_NameText.setText(sm.getValueAt(rowNum, 1).toString()); //设置学生姓名并显示
this.add(student_NameText);

sex_Label = new JLabel("性别:");
sex_Label.setBounds(78, 128, 30, 20);
this.add(sex_Label);

sex_Text = new JTextField();
sex_Text.setBounds(116, 128, 60, 20);
sex_Text.setEditable(false);//不可编辑
sex_Text.setText(sm.getValueAt(rowNum, 2).toString()); //设置学生性别并显示
this.add(sex_Text);

grade_Label = new JLabel("年级:");
grade_Label.setBounds(78, 168, 30, 20);
this.add(grade_Label);

grade_Text = new JTextField();
grade_Text.setBounds(116, 168, 150, 20);
grade_Text.setEditable(false);
grade_Text.setText(sm.getValueAt(rowNum, 3).toString()); //设置年级并显示
this.add(grade_Text);

classe_Label = new JLabel("班级:");
classe_Label.setBounds(78, 208, 30, 20);
this.add(classe_Label);

classe_Text = new JTextField();
classe_Text.setBounds(116, 208, 150, 20);
classe_Text.setEditable(false);
classe_Text.setText(sm.getValueAt(rowNum, 4).toString());
this.add(classe_Text);

department_Label = new JLabel("院系:");
department_Label.setBounds(78, 248, 30, 20);

this.add(department_Label);

department_Text = new JTextField();
department_Text.setEditable(false);
department_Text.setText(sm.getValueAt(rowNum, 5).toString());
department_Text.setBounds(116, 248, 150, 20);
this.add(department_Text);

major_Label = new JLabel("专业:");
major_Label.setBounds(78, 288, 30, 20);
this.add(major_Label);

major_Text = new JTextField();
major_Text.setEditable(false);
major_Text.setBounds(116, 288, 150, 20);
major_Text.setText(sm.getValueAt(rowNum, 6).toString());
this.add(major_Text);

confirm_Button = new JButton("确认");
//注册"确定"按钮事件监听
confirm_Button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
jd.dispose();//关闭当前窗口
}
});
confirm_Button.setBounds(150, 330, 60, 25);

this.add(confirm_Button);


WindowUtil.setFrameCenter(this);
this.setResizable(false);
this.setVisible(true);
}
}

修改学生信息
根据查询条件或者选中的条件来修改,所选中的学生
修改学生信息
删除学生信息
删除学生信息
根据查询条件或者选中的条件来删除,所选中的学生
查询 修改 删除学生 信息时都具有条件查询和多条件查询的功能
查询和多条件查询的代码

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package studentsystem.frame;

import studentsystem.dao.ManageHelper;
import studentsystem.model.StudentModel;
import studentsystem.util.CreateSql;
import studentsystem.util.WindowUtil;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;


//多条件查询界面
public class ConditionsQueryFrame extends JDialog{
private JLabel student_ID; //"学号"标签
private JLabel student_Name; //"姓名"标签
private JLabel sex_Label; //"性别"标签。l
private JLabel classe_Label; //"班级"标签
private JLabel grade_Label; //"年级标签"
private JLabel major_Label; //"专业"标签
private JLabel department_Label; //"所属院系"标签
private JTextField student_IDText; //"学号"文本域
private JTextField student_NameText; //"姓名"文本域
private JTextField sex_Text; //性别选项
private JTextField grade_Text; //年级选项
private JTextField department_Text; //系别
private JTextField major_Text; //专业
private JTextField classe_Text; //班级
private JButton conditions_button; //多条件查询按钮
private ManageHelper helper; //数据库业务处理对象
private JDialog jd; //当前窗口
/**
*
* @param owner 它的父窗口
* @param title 窗口名
* @param modal 指定的模式窗口,还有非模式窗口
*/
public ConditionsQueryFrame(JDialog owner, String title, boolean modal,JTable jt){
super(owner, title, modal);
this.jd = this;
this.setLayout(null);

student_ID = new JLabel("学号:");
student_ID.setBounds(29, 19, 30, 20);
this.add(student_ID);

student_IDText = new JTextField();
student_IDText.setBounds(65, 19, 100, 20);
this.add(student_IDText);

student_Name = new JLabel("姓名:");
student_Name.setBounds(200, 19, 30, 20);
this.add(student_Name);

student_NameText = new JTextField();
student_NameText.setBounds(240, 19, 100, 20);
this.add(student_NameText);

sex_Label = new JLabel("性别:");
sex_Label.setBounds(29, 50, 30, 20);
this.add(sex_Label);

sex_Text = new JTextField();
sex_Text.setBounds(65, 50, 100, 20);
this.add(sex_Text);

grade_Label = new JLabel("年级:");
grade_Label.setBounds(200, 50, 30, 20);
this.add(grade_Label);

grade_Text = new JTextField();
grade_Text.setBounds(240, 50, 100, 20);
this.add(grade_Text);

department_Label = new JLabel("院系:");
department_Label.setBounds(29, 83, 30, 20);
this.add(department_Label);

department_Text = new JTextField();
department_Text.setBounds(65, 83, 100, 20);
this.add(department_Text);

major_Label = new JLabel("专业:");
major_Label.setBounds(200, 83, 30, 20);
this.add(major_Label);

major_Text = new JTextField();
major_Text.setBounds(240, 83, 100, 20);
this.add(major_Text);

classe_Label = new JLabel("班级:");
classe_Label.setBounds(29,116, 30, 20);
this.add(classe_Label);

classe_Text = new JTextField();
classe_Text.setBounds(65, 116, 100, 20);
this.add(classe_Text);

conditions_button = new JButton("多条件查询");
conditions_button.setBounds(230, 130, 100, 30);
//注册"多条件查询"按钮事件监听
conditions_button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
String id = student_IDText.getText().trim();
String name = student_NameText.getText().trim();
String sex = sex_Text.getText().trim();
String grade = grade_Text.getText().trim();
String department = department_Text.getText().trim();
String major = major_Text.getText().trim();
String classe = classe_Text.getText().trim();
if(id.equals("")&&name.equals("")&&sex.equals("")&&grade.equals("")&&department.equals("")&&major.equals("")&&classe.equals("")){
JOptionPane.showMessageDialog(jd, "条件不能为空!", "", JOptionPane.WARNING_MESSAGE);
return ;
}else{
String sql = CreateSql.getConditions_Sql(id, name, sex, grade, department, major, classe);
StudentModel sm = new StudentModel(sql,jd);
jt.setModel(sm);
jd.dispose();
}

}
});
this.add(conditions_button);


this.setSize(411, 222);
// 设置窗体大小不可调整
this.setResizable(false);
WindowUtil.setFrameCenter(this);
this.setVisible(true);
}
}

后续代码放程序包里主要讲设计思路

成绩管理模块

成绩添加
添加成绩:设置多条件窗口,及查询窗口,表格监听,当选中表格的一行时,可以添加成绩
添加学生成绩
提示该学生已经有成绩了
当选中表格的一行已经有成绩时,提示
提示已经有成绩了
成绩修改
成绩修改
成绩查询
查询成绩
多条件查询
多条件查询
成绩统计
成绩统计

帮助模块

帮助

在浏览器打开帮助的网站,就可以进入我的博客,获得帮助啦。
源码下载地址
https://github.com/xiaoyi-s/StudentManageSystem
源码下载地址
个人博客地址
https://xiaoyi-s.github.io/
个人博客地址
功能如有错误欢迎指正
欢迎留言共同学习
在个人博客,CSDN,github上留言都可以

-------------本文结束感谢您这么好看还看我的文章-------------