声明:未经允许,请勿转载
运行结果
学生请假管理系统需求分析
GUI 编程
事件处理
数据库编程
部分代码
项目结构
文章来源:https://www.toymoban.com/news/detail-716956.html
实体类 Admin.java
package info;
public class Admin {
//管理员信息类
private String UserIdentity; //用户身份,用于判断登录用户是学生Student还是教师Teacher还是管理员Admin
private String id; // 工号,即用户账号
private String password; //用户密码
private String name; // 姓名
private String sex; // 性别
private String age; //年龄
private String jobTitle; //职称
private String Phone;//联系电话
private String address; // 家庭住址
// 2120220087 010718 小庄 男 21 电气与计算机工程学院 教师 15018722839 广东省广州市
//("Admin"," 2120220087 ","1 ","小庄"," 男 ","21 "," 教务处主任"," 15018722839"," 广东省广州市");
public Admin() {
}
public Admin(String userIdentity, String id, String password, String name, String sex, String age, String jobTitle, String phone, String address) {
this.UserIdentity = userIdentity;
this.id = id;
this.password = password;
this.name = name;
this.sex = sex;
this.age = age;
this.jobTitle = jobTitle;
this.Phone = phone;
this.address = address;
}
public String getUserIdentity() {
return UserIdentity;
}
public void setUserIdentity(String userIdentity) {
UserIdentity = userIdentity;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public String getPhone() {
return Phone;
}
public void setPhone(String phone) {
Phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
LeaveData.java
package info;
public class LeaveData {
//请假信息表单
private String num; // 编号
private String name; // 姓名
private String ID; // 学号
private String sex;//性别
private String age;//年龄
private String faculties; // 所在院系
private String profession;//专业名称
private String className; // 班级名称
private String Phone;//联系电话
private String requestData; //申请日期
private String StartTime; // 开始时间
private String EndEime; // 结束时间
private String reason;//申请理由
private String Approver;//审核人
private String ApprovalReason; //审核意见
private String state;//状态
/**
* 状态:
* 编辑保存 ----未提交
* 请假----请假申请中
* 请假审批通过 ---请假成功
* 请假审批不通过--请假失败
* 销假 ---销假申请中
* 销假审批通过--销假成功
* 销假审批不通过---销假失败
*/
public LeaveData() {
}
public LeaveData(String num, String name, String ID, String sex, String age, String faculties, String profession,
String className, String phone, String requestData, String startTime, String endEime, String approver,
String approvalReason, String reason, String state) {
this.num = num;
this.name = name;
this.ID = ID;
this.sex = sex;
this.age = age;
this.faculties = faculties;
this.profession = profession;
this.className = className;
this.Phone = phone;
this.requestData = requestData;
this.StartTime = startTime;
this.EndEime = endEime;
this.Approver = approver;
this.ApprovalReason = approvalReason;
this.reason = reason;
this.state = state;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getFaculties() {
return faculties;
}
public void setFaculties(String faculties) {
this.faculties = faculties;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public String getPhone() {
return Phone;
}
public void setPhone(String phone) {
Phone = phone;
}
public String getRequestData() {
return requestData;
}
public void setRequestData(String requestData) {
this.requestData = requestData;
}
public String getStartTime() {
return StartTime;
}
public void setStartTime(String startTime) {
StartTime = startTime;
}
public String getEndEime() {
return EndEime;
}
public void setEndEime(String endEime) {
EndEime = endEime;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public String getApprover() {
return Approver;
}
public void setApprover(String approver) {
Approver = approver;
}
public String getApprovalReason() {
return ApprovalReason;
}
public void setApprovalReason(String approvalReason) {
ApprovalReason = approvalReason;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
}
UserLogin.java
package GUI;
import info.Admin;
import info.Student;
import info.Teacher;
import info.User;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Objects;
import static toolbox.LeaveDataBase.getConnection;
public class UserLogin extends JFrame implements ActionListener {
private JTextField fieldAccount = new JTextField(); //账号输入框文本
private JPasswordField fieldPassword = new JPasswordField();//密码输入框文本
private JButton buttonLogin = new JButton("登 录");
static User user = new User();//用于存储登录者的账户密码及身份
Admin admin;
Teacher teacher;
Student student;
public static void main(String[] args) {
initGobalFont(new Font("宋体", Font.PLAIN, 12));
try {
//org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
new UserLogin();
} catch (Exception e) {
e.printStackTrace();
}
}
public UserLogin() {
this.setTitle("登录系统");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭窗口
this.setBounds(500, 150, 630, 450);//设置页面大小
this.setResizable(false);//设置页面不可拖拽改变大小
this.setLocationRelativeTo(null); // 设置登录界面居中
this.getContentPane().setLayout(null);
this.setVisible(true);
JLabel titleLabel = new JLabel("学生请假管理系统");
titleLabel.setFont(new Font("华文行楷", Font.PLAIN, 30));
titleLabel.setIcon(new ImageIcon(Objects.requireNonNull(UserLogin.class.getResource("/images/logo.png"))));
titleLabel.setBounds(150, 70, 350, 65);
this.getContentPane().add(titleLabel);
//用户账号
JLabel labelAccount = new JLabel("账号:");
labelAccount.setFont(new Font("宋体", Font.PLAIN, 20));
labelAccount.setAlignmentY(CENTER_ALIGNMENT);
labelAccount.setIcon(new ImageIcon(Objects.requireNonNull(UserLogin.class.getResource("/images/userName.png"))));
labelAccount.setBounds(150, 172, 81, 30);
fieldAccount.setBounds(243, 172, 200, 30);
//fieldAccount.setText("1");///==========
this.getContentPane().add(labelAccount);
this.getContentPane().add(fieldAccount, BorderLayout.CENTER);
fieldAccount.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
public void changedUpdate(DocumentEvent e) {//这是更改操作的处理
user.setAccount(fieldAccount.getText().trim());//trim()方法用于去掉你可能误输入的空格号
}
public void insertUpdate(DocumentEvent e) {//这是插入操作的处理
user.setAccount(fieldAccount.getText().trim());
}
public void removeUpdate(DocumentEvent e) {//这是删除操作的处理
user.setAccount(fieldAccount.getText().trim());
}
}
);
// 用户密码
JLabel labelPwd = new JLabel("密码:");
labelPwd.setFont(new Font("宋体", Font.PLAIN, 20));
labelPwd.setAlignmentY(CENTER_ALIGNMENT);
labelPwd.setIcon(new ImageIcon(Objects.requireNonNull(UserLogin.class.getResource("/images/password.png"))));
labelPwd.setBounds(150, 222, 81, 30);
fieldPassword.setBounds(243, 222, 200, 30);
//fieldPassword.setText("1");///
this.getContentPane().add(labelPwd);
this.getContentPane().add(fieldPassword, BorderLayout.CENTER);
fieldPassword.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
public void changedUpdate(DocumentEvent e) {//这是更改操作的处理
user.setPassword(fieldPassword.getText().trim());//trim()方法用于去掉你可能误输入的空格号
}
public void insertUpdate(DocumentEvent e) {//这是插入操作的处理
user.setPassword(fieldPassword.getText().trim());
}
public void removeUpdate(DocumentEvent e) {//这是删除操作的处理
user.setPassword(fieldPassword.getText().trim());
}
}
);
// 登陆按钮
buttonLogin.setBounds(275, 282, 95, 30);
buttonLogin.setFont(new Font("宋体", Font.PLAIN, 13));
buttonLogin.setIcon(new ImageIcon(Objects.requireNonNull(UserLogin.class.getResource("/images/login.png"))));
this.getContentPane().add(buttonLogin);
//去掉按钮文字周围的焦点框
buttonLogin.setFocusPainted(false);
buttonLogin.addActionListener(this);
this.setVisible(true);
this.revalidate();
this.repaint();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == buttonLogin) {
boolean LoginUser = false;
try {
LoginUser = verifyAccount(user.getAccount(), user.getPassword());
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
if (LoginUser) {
//判断权限,加载相应面板
if (user.getUserIdentity().equals("Student")) {
JOptionPane.showMessageDialog(this, "账号密码正确,即将进入系统学生端!", "提示", JOptionPane.INFORMATION_MESSAGE);// 提示
new MainWindow(student);
} else if (user.getUserIdentity().equals("Teacher")) {
JOptionPane.showMessageDialog(this, "账号密码正确,即将进入系统教师端!", "提示", JOptionPane.INFORMATION_MESSAGE);//
new MainWindow(teacher);
} else if (user.getUserIdentity().equals("Admin")) {
JOptionPane.showMessageDialog(this, "账号密码正确,即将进入系统管理端!", "提示", JOptionPane.INFORMATION_MESSAGE);//
new MainWindow(admin);
}
this.dispose(); // 关闭当前窗口
}
}
}
private boolean verifyAccount(String account, String password) throws SQLException {
// 判断输入账号或密码为空与空格的情况
if (account == null || "".equals(account.trim()) || password == null || "".equals(password.trim())) {
// 警示框,"Title",JOptionPane.WARNING_MESSAGE
JOptionPane.showMessageDialog(null, "账号与密码均不能为空!", "警告", JOptionPane.WARNING_MESSAGE);
} else {
Connection conn = getConnection();
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
//查询学生表
ResultSet rs = stmt.executeQuery("SELECT *FROM StudentList WHERE id = '" + account + "' AND password = '" + password + "';");
if (!rs.isBeforeFirst()) {
//若学生表中不存在,则查询教师表
rs = stmt.executeQuery("SELECT *FROM TeacherList WHERE id = '" + account + "' AND password = '" + password + "';");
}
if (!rs.isBeforeFirst()) {
//若学生表与教师表中不存在,则查询管理员表
rs = stmt.executeQuery("SELECT *FROM AdminList WHERE id = '" + account + "' AND password = '" + password + "';");
}
if (!rs.isBeforeFirst()) {
//若学生表与教师表与管理员表中不存在,则提示账户密码错误
//错误提示框,"Title",JOptionPane.ERROR_MESSAGE
JOptionPane.showMessageDialog(this, "账号密码错误,请重新登录!", "警告", JOptionPane.ERROR_MESSAGE);
fieldPassword.setText(null);
return false;
}
while (rs.next()) {
user.setUserIdentity(rs.getString(1));
//创建对应身份信息的实体类并赋值
if (user.getUserIdentity().equals("Student")) {
student = new Student(rs.getString(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getString(6),
rs.getString(7),
rs.getString(8),
rs.getString(9),
rs.getString(10),
rs.getString(11));
} else if (user.getUserIdentity().equals("Teacher")) {
teacher = new Teacher(rs.getString(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getString(6),
rs.getString(7),
rs.getString(8),
rs.getString(9),
rs.getString(10));
} else if (user.getUserIdentity().equals("Admin")) {
admin = new Admin(rs.getString(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getString(6),
rs.getString(7),
rs.getString(8),
rs.getString(9));
}
}
rs.close();
stmt.close();
return true;
}
return false;
}
//全局字体 https://blog.csdn.net/lifaxing/article/details/79365078
public static void initGobalFont(Font font) {
FontUIResource fontResource = new FontUIResource(font);
for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements(); ) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof FontUIResource) {
UIManager.put(key, fontResource);
}
}
}
}
MainWindow.java
package GUI;
import info.Admin;
import info.Student;
import info.Teacher;
import panel.PanelAdmin;
import panel.PanelStudent;
import panel.PanelTeacher;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Objects;
public class MainWindow {
public static JFrame frame;
public static JTabbedPane tabbedPane;
public static JLabel label_status;
private JMenuBar menuBar;
private JMenuItem mntmNewMenuItem_exit, menuItem_setting, mntmNewMenuItem_help;
private JPanel panel_status; //登录状态
//参数 学生
public MainWindow(Student student) {
windowLoads();
new PanelStudent(student);
}
//参数 教师
public MainWindow(Teacher teacher) {
windowLoads();
new PanelTeacher(teacher);
}
//参数 管理员
public MainWindow(Admin admin) {
windowLoads();
new PanelAdmin();
}
private void windowLoads() {
frame = new JFrame();
// 设置窗口标题图标
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\ZHUANG\\Desktop\\LeaveSystem1\\LeaveSystem\\src\\images\\icon.png"));
frame.setTitle("学生请假管理系统");
frame.setBounds(0, 0, 820, 626);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭窗口
frame.getContentPane().setLayout(null);
frame.setVisible(true);
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBounds(0, 30, 820, 522);
frame.getContentPane().add(tabbedPane);
frame.setResizable(false);//设置页面不可拖拽改变大小
frame.setLocationRelativeTo(null); // 设置登录界面居中
// 系统菜单
menuBar = new JMenuBar();
menuBar.setBounds(0, 0, 820, 21);
frame.getContentPane().add(menuBar);
JMenu mnNewMenu = new JMenu("系统");
menuBar.add(mnNewMenu);
mnNewMenu.setIcon(new ImageIcon(Objects.requireNonNull(UserLogin.class.getResource("/images/base.png"))));
menuItem_setting = new JMenuItem("设置");
mnNewMenu.add(menuItem_setting);
mntmNewMenuItem_exit = new JMenuItem("直接退出");
mnNewMenu.add(mntmNewMenuItem_exit);
mntmNewMenuItem_exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Object[] options = {"确认", "取消"}; //定义按钮上的文字
int n = JOptionPane.showOptionDialog(null, "是否退出本账户?", "提示", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
if (n == 0) {
frame.dispose();
new UserLogin();
}
}
});
JMenu mnNewMenu_1 = new JMenu("关于");
menuBar.add(mnNewMenu_1);
mntmNewMenuItem_help = new JMenuItem("帮助");
mnNewMenu_1.add(mntmNewMenuItem_help);
//状态栏
panel_status = new JPanel();
panel_status.setLocation(0, 570);
panel_status.setSize(820, 22);
panel_status.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));//边框
frame.getContentPane().add(panel_status);
label_status = new JLabel("登录成功");
label_status.setBounds(207, 1, 820, 25);
JProgressBar progressBar = new JProgressBar();
progressBar.setBounds(0, 1, 200, 25);
panel_status.setLayout(null);
panel_status.add(label_status);
panel_status.add(progressBar);
frame.setVisible(true);
}
}
leaveList.java
package Functional.Student;
import info.LeaveData;
import info.Student;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import static toolbox.LeaveDataBase.getConnection;
public class leaveList extends JFrame {
public leaveList(Student student) {
List<LeaveData> dataList = new ArrayList<LeaveData>();
try {
//查询数据库对应该学生学号的数据
Connection conn = getConnection();
Statement stmt = null;
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("SELECT *FROM LeaveData WHERE id='" + student.getId() + "';");
if (rs.isBeforeFirst()) {
while (rs.next()) {
LeaveData leaveData = new LeaveData();
leaveData.setNum(rs.getString(1));
leaveData.setName(rs.getString(2));
leaveData.setID(rs.getString(3));
leaveData.setSex(rs.getString(4));
leaveData.setAge(rs.getString(5));
leaveData.setFaculties(rs.getString(6));
leaveData.setProfession(rs.getString(7));
leaveData.setClassName(rs.getString(8));
leaveData.setPhone(rs.getString(9));
leaveData.setRequestData(rs.getString(10));
leaveData.setStartTime(rs.getString(11));
leaveData.setEndEime(rs.getString(12));
leaveData.setReason(rs.getString(13));
leaveData.setApprover(rs.getString(14));
leaveData.setApprovalReason(rs.getString(15));
leaveData.setState(rs.getString(16));
dataList.add(leaveData);
}
} else {
JOptionPane.showMessageDialog(this, "无请假历史数据!", "提示", JOptionPane.ERROR_MESSAGE);
}
rs.close();
stmt.close();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
String[] columnName = new String[]{"编号", "申请日期", "开始时间", "结束时间", "申请理由", "审核人", "审核意见", "状态"};
String[][] columnDate = new String[dataList.size()][];
for (int i = 0; i < dataList.size(); i++) {
LeaveData d = dataList.get(i);
columnDate[i] = new String[]{d.getNum(), d.getRequestData(), d.getStartTime(), d.getEndEime(), d.getReason(), d.getApprover(), d.getApprovalReason(), d.getState()};
}
this.setLayout(null); // 绝对布局
setSize(680, 522); // 设置界面大小
this.setVisible(true);
this.setTitle("查询");
setResizable(false); // 设置界面大小不可改变
setLocationRelativeTo(null); // 设置登录界面居中
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 设置默认关闭操作
JLabel title = new JLabel("请假信息列表");
title.setFont(new Font("宋体", Font.PLAIN, 22));
title.setBounds(260, 10, 180, 50);
this.add(title);
DefaultTableModel dtm = new DefaultTableModel(columnDate, columnName);
JTable jtable = new JTable(dtm) {
//可选择表格行,但不可编辑
public boolean isCellEditable(int row, int column) {
return false;
}
};
jtable.setShowVerticalLines(false); //去掉竖线
DefaultTableCellRenderer r = new DefaultTableCellRenderer(); //此三行 内容居中
r.setHorizontalAlignment(JLabel.CENTER);
jtable.getTableHeader().setReorderingAllowed(false);// 表头不可拖动
jtable.setDefaultRenderer(Object.class, r);
JScrollPane scrollPane = new JScrollPane(); //直接添加容器,表头不显示
scrollPane.setBounds(30, 70, 600, 370);
this.add(scrollPane);
scrollPane.setViewportView(jtable);
//给table加上一个鼠标事件监听器对象
jtable.addMouseListener(new MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent e) {
//是否左建双击
if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
//添加双击后的
int count = jtable.getSelectedRow();//获取你选中的行号
String[] datarow = new String[]{"", "", "", "", "", "", "", ""};
for (int i = 0; i < datarow.length; i++) {
String getname = jtable.getValueAt(count, i).toString();//读取获取行号的某一列的值
datarow[i] = getname;
}
new JtablePopUps(datarow);
}
}
});
JLabel tip = new JLabel("tip:双击表行可以查看其详细信息!");
tip.setFont(new Font("宋体", Font.PLAIN, 12));
tip.setBounds(30, 435, 300, 50);
this.add(tip);
}
}
注:完整内容可下载查看完整报告
下载链接
https://download.csdn.net/download/weixin_66397563/87976888文章来源地址https://www.toymoban.com/news/detail-716956.html
到了这里,关于【java 程序设计实训】学生请假管理系统的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!