1.系统简介和开发背景
该同学工作积极主动、高效,学习认真,待人诚恳,能够做到服从指挥、认真听取老同志的指导,不怕苦、不怕累,表现有较强的求知欲,积极观察、体验、思考,并能够灵活运用自己的知识解决工作中遇到的实际问题。
本项目使用:jdk1.8、java、mysql、eclipse/idea
2.功能分析
学生管理模块:
(1)增删改查学生信息,当学生还有学习的学员时,不能删除学生信息;
(2)按学生查询选择课程信息,支持名称模糊查询;
学员管理模块:
(1)增删改查学员信息;
(2)按学员名查询学员信息,支持学员名模糊查询和分页显示;
3.功能模块图及说明
管理员新增学生信息时填写对应的信息,如姓名、课程号等。后台代码将在页面创建的信息提交到控制层进行数据验证,如果信息填写符合规则且数据唯一,则该数据将存储到本地数据库中,否则添加失败。管理员进行登录时首先点击跳转到管理员登录界面按钮,输入相应的信息点击登录。登录界面流程图如图4-1所示,添加学生功能流程图如图4-2所示。
图4-1 登录界面流程图
图4-2 添加学生功能流程图
管理员修改学生职位信息时可以从快速搜索区,输入学生名称进行查询。按要求填写信息后保存,第一条数据为新添加的数据;管理员修改部门信息时,依次填写好对应的信息,后台代码将信息提交到控制层进行数据验证,验证通过则修改成功,数据存储到本地数据库里,否则失败。职位修改功能流程图如图4-3所示,添加部门功能流程图如图4-4所示。
图4-3 学生信息修改流程图
图4-4 添加学生功能流程图
学生信息管理系统的主要模块包括增加、删除、修改和查询等操作,以下是这些操作的简单描述:
增加模块:该模块允许管理员将新的学生信息添加到系统中。这通常涉及到填写一个包含各种字段(例如姓名、性别、出生日期、学号、班级等)的表单。系统将检查输入的数据是否有效,例如,学号是否唯一,然后将其添加到数据库中。
删除模块:在此模块中,管理员可以选择并删除系统中的学生信息。例如,当一个学生转学或退学时,管理员可能需要从系统中删除他们的记录。
修改模块:此模块允许管理员更新系统中已有的学生信息。例如,如果学生的家庭地址发生变化,管理员可以通过此模块更新学生的家庭地址信息。在修改数据时,管理员需要确保数据的完整性和准确性。
查询模块:此模块允许管理员和学生查询系统中的学生信息。管理员可以查看学生的全部信息,而学生通常只能查看与他们自己相关的信息,例如他们的成绩、等。
4.部分代码展示
4.1数据库表设计
CREATE TABLE `admin` (
`Aid` int(11) NOT NULL,
`Aname` varchar(30) NOT NULL,
`Apwd` varchar(10) NOT NULL,
PRIMARY KEY (`Aid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = CREATE TABLE `course` (
`Cnum` int(11) NOT NULL AUTO_INCREMENT,
`Cno` int(11) NOT NULL,
`Cname` varchar(20) NOT NULL,
`Ctime` int(11) NOT NULL,
`Ccredit` int(11) NOT NULL,
PRIMARY KEY (`Cnum`,`Cno`),
KEY `Cname` (`Cname`),
KEY `Cno` (`Cno`)
CREATE TABLE `score` (
`Sno` int(11) NOT NULL,
`Sname` varchar(20) NOT NULL,
`Cno` int(11) NOT NULL,
`Cname` varchar(20) DEFAULT NULL,
`Sscore` decimal(10,0) DEFAULT '0',
`Rescore` decimal(10,0) DEFAULT '0',
PRIMARY KEY (`Sno`,`Cno`),
KEY `Cname` (`Cname`),
KEY `Cno` (`Cno`),
KEY `Sname` (`Sname`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for user_train_re //学生,用户联系表
-- ----------------------------
CREATE TABLE `student` (
`Sno` int(11) NOT NULL,
`Sname` varchar(30) NOT NULL,
`Sgender` char(2) NOT NULL,
`Sage` int(11) NOT NULL,
`Sbirthday` datetime DEFAULT '1999-01-01 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
`Sclass` varchar(10) NOT NULL,
`Smajor` varchar(20) NOT NULL,
`Sdept` varchar(20) NOT NULL,
`Spwd` varchar(10) NOT NULL DEFAULT '123',
PRIMARY KEY (`Sno`),
KEY `Sname` (`Sname`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4.2后台管理界面设计
登录
package com.system.view;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import com.system.dao.StudentDao;
import com.system.dao.UserDao;
public class Login extends JFrame {
private JPanel contentPane;
private JTextField usernameField;
private JPasswordField passwordField;
private JComboBox comboBox;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Login() {
setTitle("学生信息管理系统");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 689, 428);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(0, 0, 673, 389);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("学生信息管理系统");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
lblNewLabel.setBounds(114, 36, 393, 55);
panel.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("用户名:");
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_1.setBounds(106, 112, 145, 31);
panel.add(lblNewLabel_1);
JLabel lblNewLabel_1_1 = new JLabel("密码:");
lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_1_1.setBounds(106, 173, 145, 31);
panel.add(lblNewLabel_1_1);
JLabel lblNewLabel_1_2 = new JLabel("身份:");
lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_2.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_1_2.setBounds(106, 242, 145, 31);
panel.add(lblNewLabel_1_2);
usernameField = new JTextField();
usernameField.setBounds(227, 112, 249, 37);
panel.add(usernameField);
usernameField.setColumns(10);
passwordField = new JPasswordField();
passwordField.setBounds(227, 170, 249, 37);
panel.add(passwordField);
String[] a = new String[] { "管理员", "学生" };
comboBox = new JComboBox(a);
comboBox.setBounds(227, 237, 249, 42);
panel.add(comboBox);
JButton btnNewButton = new JButton("登录");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// 获取文本框数据
String username = usernameField.getText();
String password = passwordField.getText();
String type = (String) comboBox.getSelectedItem();
// 判断是否为空
if (username.equals("") || password.equals("")) {
JOptionPane.showMessageDialog(null, "用户名或密码不能为空!");
} else {
if ("管理员".equals(type)) {
// 管理员登录
try {
UserDao log = new UserDao();
boolean istrue = log.LoginCheck(username, password);
if (istrue) {
JOptionPane.showMessageDialog(null, "登录成功!");
String a = "admin";
setVisible(false);
new Bg(a).setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误!");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
} else {
// 学生登录
try {
StudentDao log = new StudentDao();
boolean istrue = log.LoginCheck(username, password);
if (istrue) {
JOptionPane.showMessageDialog(null, "登录成功!");
String a = "学生"; // 不可修改,控制权限!
setVisible(false);
new Bg(a).setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误!");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
}
});
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton.setBounds(132, 308, 108, 37);
panel.add(btnNewButton);
JButton btnNewButton_1 = new JButton("重置");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
usernameField.setText("");
passwordField.setText("");
}
});
btnNewButton_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton_1.setBounds(399, 308, 108, 37);
panel.add(btnNewButton_1);
}
}
查询操作
package com.system.view;
import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;
import javax.swing.JButton;
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;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import com.system.dao.UserDao;
import com.system.entity.Student;
public class StudentSelect extends JFrame {
private JPanel contentPane;
private JTextField keyField;
private JTable table;
private JScrollPane scrollPane;
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// StudentSelect frame = new StudentSelect();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
/**
* Create the frame.
*/
public StudentSelect(String flag) {
setTitle("学生信息管理系统");
setBounds(100, 100, 845, 558);
contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(SystemColor.activeCaption);
panel.setBounds(0, 0, 848, 51);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("学生基本信息");
lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(325, 10, 222, 31);
panel.add(lblNewLabel);
JPanel panel_1 = new JPanel();
panel_1.setBackground(Color.WHITE);
panel_1.setBounds(0, 49, 829, 51);
contentPane.add(panel_1);
panel_1.setLayout(null);
JLabel lblNewLabel_1 = new JLabel("学号:");
lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_1.setBounds(225, 10, 54, 31);
panel_1.add(lblNewLabel_1);
// 表头
final Vector vector = new Vector();
vector.add("学号");
vector.add("姓名");
vector.add("性别");
vector.add("年龄");
vector.add("班级");
vector.add("专业");
vector.add("系别");
// 表里面的数据
Vector tData = new Vector();
keyField = new JTextField();
keyField.setBounds(273, 10, 190, 31);
panel_1.add(keyField);
keyField.setColumns(10);
JButton btnNewButton = new JButton("查询");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// 根据学号查询学生
String key = keyField.getText();
if (key.equals("")) {
JOptionPane.showMessageDialog(null, "学号不能为空!");
} else {
try {
UserDao user = new UserDao();
List<Student> list = user.Select(key, null);
tData.clear();
for (int i = 0; i < list.size(); i++) {
Vector v = new Vector();
v.add(list.get(i).getSno());
v.add(list.get(i).getName());
v.add(list.get(i).getGender());
v.add(list.get(i).getAge());
v.add(list.get(i).getClas());
v.add(list.get(i).getMajor());
v.add(list.get(i).getDept());
tData.add(v);
}
table = new JTable(tData, vector);
scrollPane.setViewportView(table);
// table = new JTable(tData, vector);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton.setBounds(483, 10, 67, 31);
panel_1.add(btnNewButton);
scrollPane = new JScrollPane();
scrollPane.setBounds(0, 98, 829, 421);
contentPane.add(scrollPane);
try {
UserDao user = new UserDao();
List<Student> list = user.res();
tData.clear();
for (int i = 0; i < list.size(); i++) {
Vector v = new Vector();
v.add(list.get(i).getSno());
v.add(list.get(i).getName());
v.add(list.get(i).getGender());
v.add(list.get(i).getAge());
v.add(list.get(i).getClas());
v.add(list.get(i).getMajor());
v.add(list.get(i).getDept());
tData.add(v);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
table = new JTable(tData, vector);
scrollPane.setViewportView(table);
}
}
添加操作
package com.system.view;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import com.system.dao.UserDao;
public class StudentAdd extends JFrame {
private JPanel contentPane;
private JTextField snoField;
private JTextField snameField;
private JTextField sageField;
private JTextField sclassField;
private JTextField smajorField;
private JTextField sdeptField;
private JComboBox comboBox;
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// StudentAdd frame = new StudentAdd();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
/**
* Create the frame.
*/
public StudentAdd(String admin) {
setBounds(100, 100, 723, 506);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setBounds(0, 0, 707, 467);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("添加学生");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel.setBounds(237, 28, 172, 36);
panel.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("学号:");
lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 15));
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setBounds(201, 81, 53, 30);
panel.add(lblNewLabel_1);
snoField = new JTextField();
snoField.setBounds(267, 80, 194, 36);
panel.add(snoField);
snoField.setColumns(10);
JLabel lblNewLabel_1_1 = new JLabel("姓名:");
lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.BOLD, 15));
lblNewLabel_1_1.setBounds(201, 129, 53, 30);
panel.add(lblNewLabel_1_1);
JLabel lblNewLabel_1_2 = new JLabel("年龄:");
lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_2.setFont(new Font("微软雅黑", Font.BOLD, 15));
lblNewLabel_1_2.setBounds(201, 178, 53, 30);
panel.add(lblNewLabel_1_2);
JLabel lblNewLabel_1_3 = new JLabel("班级:");
lblNewLabel_1_3.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_3.setFont(new Font("微软雅黑", Font.BOLD, 15));
lblNewLabel_1_3.setBounds(201, 231, 53, 30);
panel.add(lblNewLabel_1_3);
JLabel lblNewLabel_1_4 = new JLabel("专业:");
lblNewLabel_1_4.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_4.setFont(new Font("微软雅黑", Font.BOLD, 15));
lblNewLabel_1_4.setBounds(201, 277, 53, 30);
panel.add(lblNewLabel_1_4);
JLabel lblNewLabel_1_5 = new JLabel("系别:");
lblNewLabel_1_5.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_5.setFont(new Font("微软雅黑", Font.BOLD, 15));
lblNewLabel_1_5.setBounds(201, 330, 53, 30);
panel.add(lblNewLabel_1_5);
JLabel lblNewLabel_1_6 = new JLabel("性别:");
lblNewLabel_1_6.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_6.setFont(new Font("微软雅黑", Font.BOLD, 15));
lblNewLabel_1_6.setBounds(201, 381, 53, 30);
panel.add(lblNewLabel_1_6);
snameField = new JTextField();
snameField.setColumns(10);
snameField.setBounds(267, 126, 194, 36);
panel.add(snameField);
sageField = new JTextField();
sageField.setColumns(10);
sageField.setBounds(267, 177, 194, 36);
panel.add(sageField);
sclassField = new JTextField();
sclassField.setColumns(10);
sclassField.setBounds(267, 230, 194, 36);
panel.add(sclassField);
smajorField = new JTextField();
smajorField.setColumns(10);
smajorField.setBounds(267, 276, 194, 36);
panel.add(smajorField);
sdeptField = new JTextField();
sdeptField.setColumns(10);
sdeptField.setBounds(267, 329, 194, 36);
panel.add(sdeptField);
JButton btnNewButton = new JButton("添加");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String sno = snoField.getText();
String sname = snameField.getText();
String sage = sageField.getText();
String sclass = sclassField.getText();
String smajor = smajorField.getText();
String sdept = sdeptField.getText();
String sex = (String) comboBox.getSelectedItem();
if (sno.equals("") || sname.equals("") || sage.equals("") || sclass.equals("") || smajor.equals("")
|| sdept.equals("") || sex.equals("")) {
JOptionPane.showMessageDialog(null, "信息不完整,请填写完整!");
} else {
UserDao userDao = new UserDao();
try {
boolean istrue = userDao.insert(sno, sname, sex, sage, sclass, smajor, sdept);
if (istrue) {
JOptionPane.showMessageDialog(null, "学生信息录入成功!");
} else{
JOptionPane.showMessageDialog(null, "学生录入失败,此学号已存在!");
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton.setBounds(201, 427, 93, 30);
panel.add(btnNewButton);
JButton btnNewButton_1 = new JButton("重置");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
snoField.setText("");
snameField.setText("");
sageField.setText("");
sclassField.setText("");
smajorField.setText("");
sdeptField.setText("");
}
});
btnNewButton_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton_1.setBounds(390, 427, 93, 30);
panel.add(btnNewButton_1);
String[] a = new String[] { "男", "女" };
comboBox = new JComboBox(a);
comboBox.setBounds(267, 381, 194, 27);
panel.add(comboBox);
}
}
修改操作
package com.system.view;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import com.system.dao.UserDao;
import com.system.entity.Student;
public class StudentUpdate extends Bg {
private JPanel contentPane;
private JTextField keyField;
private JTextField snoField;
private JTextField snameField;
private JTextField sageField;
private JTextField sclassField;
private JTextField smajorField;
private JTextField sdeptField;
private JComboBox comboBox;
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// StudentUpdate frame = new StudentUpdate();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
/**
* Create the frame.
*/
public StudentUpdate(String a) {
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// setBounds(100, 100, 450, 300);
// contentPane = new JPanel();
// contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
// contentPane.setLayout(new BorderLayout(0, 0));
// setContentPane(contentPane);
super(a);
JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setBounds(166, 54, 751, 493);
getContentPane().add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("修改学生信息");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel.setBounds(270, 32, 214, 32);
panel.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("输入学号:");
lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_1.setBounds(140, 81, 81, 19);
panel.add(lblNewLabel_1);
keyField = new JTextField();
keyField.setBounds(214, 81, 182, 21);
panel.add(keyField);
keyField.setColumns(10);
JButton btnNewButton = new JButton("查询");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String key = keyField.getText();
if (key.equals("")) {
JOptionPane.showMessageDialog(null, "学号不能为空!");
} else {
UserDao user = new UserDao();
Student stu = new Student();
try {
stu = user.select(key);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (stu != null) {
snoField.setText(String.valueOf(stu.getSno()));
snameField.setText(stu.getName());
sageField.setText(String.valueOf(stu.getAge()));
sclassField.setText(stu.getClas());
smajorField.setText(stu.getMajor());
sdeptField.setText(stu.getDept());
comboBox.setSelectedItem(stu.getGender());
} else {
JOptionPane.showMessageDialog(null, "查无此生!");
}
}
}
});
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton.setBounds(429, 77, 75, 26);
panel.add(btnNewButton);
JLabel lblNewLabel_2 = new JLabel("查询学生是否存在!");
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_2.setForeground(Color.RED);
lblNewLabel_2.setFont(new Font("微软雅黑", Font.BOLD, 13));
lblNewLabel_2.setBounds(224, 110, 172, 19);
panel.add(lblNewLabel_2);
JLabel lblNewLabel_3 = new JLabel("学生基本信息:");
lblNewLabel_3.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_3.setBounds(140, 151, 182, 19);
panel.add(lblNewLabel_3);
JLabel lblNewLabel_4 = new JLabel("学号:");
lblNewLabel_4.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_4.setBounds(140, 193, 53, 21);
panel.add(lblNewLabel_4);
snoField = new JTextField();
snoField.setBounds(190, 188, 227, 32);
panel.add(snoField);
snoField.setColumns(10);
JLabel lblNewLabel_4_1 = new JLabel("姓名:");
lblNewLabel_4_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_4_1.setBounds(140, 239, 53, 21);
panel.add(lblNewLabel_4_1);
snameField = new JTextField();
snameField.setColumns(10);
snameField.setBounds(190, 235, 227, 32);
panel.add(snameField);
JLabel lblNewLabel_4_1_1 = new JLabel("年龄:");
lblNewLabel_4_1_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_4_1_1.setBounds(140, 284, 53, 21);
panel.add(lblNewLabel_4_1_1);
sageField = new JTextField();
sageField.setColumns(10);
sageField.setBounds(190, 277, 227, 32);
panel.add(sageField);
sclassField = new JTextField();
sclassField.setColumns(10);
sclassField.setBounds(190, 319, 227, 32);
panel.add(sclassField);
JLabel lblNewLabel_4_1_1_1 = new JLabel("班级:");
lblNewLabel_4_1_1_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_4_1_1_1.setBounds(140, 327, 53, 21);
panel.add(lblNewLabel_4_1_1_1);
JLabel lblNewLabel_4_1_1_1_1 = new JLabel("班级:");
lblNewLabel_4_1_1_1_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_4_1_1_1_1.setBounds(140, 327, 53, 21);
panel.add(lblNewLabel_4_1_1_1_1);
JLabel lblNewLabel_4_1_1_1_2 = new JLabel("专业:");
lblNewLabel_4_1_1_1_2.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_4_1_1_1_2.setBounds(140, 373, 53, 21);
panel.add(lblNewLabel_4_1_1_1_2);
smajorField = new JTextField();
smajorField.setColumns(10);
smajorField.setBounds(190, 369, 227, 32);
panel.add(smajorField);
JLabel lblNewLabel_4_1_1_1_2_1 = new JLabel("系别:");
lblNewLabel_4_1_1_1_2_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_4_1_1_1_2_1.setBounds(140, 416, 53, 21);
panel.add(lblNewLabel_4_1_1_1_2_1);
sdeptField = new JTextField();
sdeptField.setColumns(10);
sdeptField.setBounds(190, 411, 227, 32);
panel.add(sdeptField);
JLabel lblNewLabel_4_1_1_1_2_1_1 = new JLabel("性别:");
lblNewLabel_4_1_1_1_2_1_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_4_1_1_1_2_1_1.setBounds(140, 462, 53, 21);
panel.add(lblNewLabel_4_1_1_1_2_1_1);
String[] b = new String[] { "男", "女" };
comboBox = new JComboBox(b);
comboBox.setBounds(190, 453, 227, 30);
panel.add(comboBox);
JButton btnNewButton_1 = new JButton("保存");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String sno = snoField.getText();
String sname = snameField.getText();
String sage = sageField.getText();
String sclass = sclassField.getText();
String smajor = smajorField.getText();
String sdept = sdeptField.getText();
String sex = (String) comboBox.getSelectedItem();
UserDao userDao = new UserDao();
try {
boolean flag = userDao.update(sno, sname, sex, sage, sclass, smajor, sdept);
if (flag) {
JOptionPane.showMessageDialog(null, "修改成功!");
} else {
JOptionPane.showMessageDialog(null, "修改失败!");
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
btnNewButton_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton_1.setBounds(474, 453, 93, 30);
panel.add(btnNewButton_1);
}
}
删除操作
package com.system.view;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import com.system.dao.UserDao;
public class StudentDelete extends Bg {
private JPanel contentPane;
private JTextField keyField;
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// StudentDelete frame = new StudentDelete();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
/**
* Create the frame.
*/
public StudentDelete(String a) {
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// setBounds(100, 100, 450, 300);
// contentPane = new JPanel();
// contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
// contentPane.setLayout(new BorderLayout(0, 0));
// setContentPane(contentPane);
super(a);
JLabel lblNewLabel = new JLabel("删除学生信息");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
lblNewLabel.setBounds(442, 113, 227, 37);
getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("输入学号:");
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_1.setBounds(402, 197, 81, 27);
getContentPane().add(lblNewLabel_1);
keyField = new JTextField();
keyField.setBounds(485, 193, 184, 37);
getContentPane().add(keyField);
keyField.setColumns(10);
JButton btnNewButton = new JButton("删除");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String key = keyField.getText();
if (key.equals("")) {
JOptionPane.showMessageDialog(null, "学号不能为空!");
} else {
UserDao user = new UserDao();
try {
if (user.delete(key)) {
JOptionPane.showMessageDialog(null, "删除学生成功!");
} else {
JOptionPane.showMessageDialog(null, "删除学生失败,请检查该学号是否正确!");
}
} catch (Exception e1) {
}
}
}
});
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton.setBounds(696, 193, 102, 37);
getContentPane().add(btnNewButton);
}
}