一、项目介绍
本项目使用Java语言来实现、使用其中的图形界面话工具对系统实现图形界面化方便使用设进行操作,数据存储使用MySQL数据库,使用数据库图形界面化工具Navicat来协助开发者开发项目,Java通过JDBC来与数据库完成交互。
项目需要对象有:学生、教师、系主任、教务、课程、班级、论文
除了以上对象需要建立数据表之外我们还需要建立班级与课程之间的数据表、学生与学生选择论文之间对应的数据表、通过审批的论文的数据表方便我们的操作。
系统要实现的功能有:
- 学生、教师、系主任、教务的登录,不同的角色登录之后有不同的功能
- 学生有选课、选择论文题目的功能
- 教师有对学生信息的管理、对班级课程的管理、提交论文题目的功能
- 系主任有对学生信息的管理、对班级课程的管理、审核论文题目的功能
- 教务有对学生信息的管理、对班级课程的管理、对论文题目的功能
二、项目技术栈
Java+Swing+MySQL
三、核心代码
数据库连接工具类
public class BaseDao {
Connection conn = null;
Statement stat = null;
PreparedStatement pstat = null;
ResultSet rs = null;
public void getConnection() {
// 2 加载驱动
try {
Class.forName("com.mysql.jdbc.Driver");
// 3 建立连接
conn = DriverManager
.getConnection(
"jdbc:mysql://localhost:3307/academic?characterEncoding=utf-8",
"root", "abc123456");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getStatement() {
getConnection();
// 4 建立sql执行器
try {
stat = conn.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getPreparedStatement(String sql) {
getConnection();
// 4 建立sql执行器
try {
pstat = conn.prepareStatement(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void closeAll() {
try {
if (conn != null) {
conn.close();
}
if (stat != null) {
stat.close();
}
if (pstat != null) {
pstat.close();
}
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
变量
public class Constant {
public final static int STU_VIEW_WIDTH = 700;
public final static int STU_VIEW_HEIGHT = 600;
public final static int STU_ADD_WIDTH = 300;
public final static int STU_ADD_HEIGHT = 400;
public final static int STU_MODIFY_WIDTH = 300;
public final static int STU_MODIFY_HEIGHT = 400;
public final static String STU_TITLE = "学生管理";
public final static String STU_ADD_TITLE = "新增学生 ";
public final static String STU_MODIFY_TITLE = "修改学生";
public final static String STU_ID = "id";
public final static String STU_NAME = "姓名";
public final static String STU_SEX = "性别";
public final static String STU_AGE = "年龄";
public final static int BJ_VIEW_WIDTH = 700;
public final static int BJ_VIEW_HEIGHT = 600;
public final static int BJ_ADD_WIDTH = 300;
public final static int BJ_ADD_HEIGHT = 200;
public final static int BJ_MODIFY_WIDTH = 300;
public final static int BJ_MODIFY_HEIGHT = 200;
public final static String BJ = "班级";
public final static String BJ_TITLE = "班级管理";
public final static String BJ_ADD_TITLE = "新增班级 ";
public final static String BJ_MODIFY_TITLE = "修改班级";
public final static String BJ_ID = "id";
public final static String BJ_NAME = "名称";
public final static String BJ_STUNUMS = "班级数";
public static final Object BJ_PROMPT_SELECT = "请选择班级";
public static final Object BJ_NO_SET = "未设置班级";
public final static int SUB_VIEW_WIDTH = 700;
public final static int SUB_VIEW_HEIGHT = 600;
public final static int SUB_ADD_WIDTH = 300;
public final static int SUB_ADD_HEIGHT = 200;
public final static int SUB_MODIFY_WIDTH = 300;
public final static int SUB_MODIFY_HEIGHT = 200;
public final static String SUB_TITLE = "科目管理";
public final static String SUB_ADD_TITLE = "课程管理";
public final static String SUB_ID = "id";
public final static String SUB_NAME = "课程名称";
public final static String SUB_MODIFY_TITLE = "修改课程";
public final static String SC_TITLE = "成绩管理";
public final static String MES_SUCCESS = "成功";
public final static String MES_FAIL = "失败";
public final static String MES_ADD = "增加";
public final static String MES_MODIFY = "修改";
public final static String MES_DELETE = "删除";
public final static String MES_SEARCH = "查询";
public final static String MES_PROMPT_SELECT = "没有选中数据";
public final static String MES_PROMPT_DELETE = "是否删除数据?";
public static final String MES_SAVE = "保存";
public static final String SUB = "科目";
public static final String SUB_PROMPT_SELECT ="请选择科目";
}
程序入口类
public class loginGUI extends JFrame {
public static Student stu = null;
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField;
private JPasswordField passwordField;
private String id = null;
private String password = null;
JComboBox<Object> comboBox = new JComboBox<Object>();
String identify = "管理员";
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
loginGUI frame = new loginGUI();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
//检查输入信息是否为空
public boolean checkNull( String id, String pwd ) {
if(id.length()<1 || pwd.length()<1 ) {
JOptionPane.showMessageDialog(null,"ID与密码不能为空!");
return false;
}
return true;
}
//老师登录
public void teacherlogin( String id, String password ) throws Exception {
boolean istrue = false;
TeacherDao log= new TeacherDao();
try {
istrue = log.LoginCheck(id, password);
} catch (SQLException e1) {
e1.printStackTrace();
}
if(istrue) {
new TeacherView().init();
dispose();
}else{
JOptionPane.showMessageDialog(null,"用户名或密码错误!","登陆失败",JOptionPane.ERROR_MESSAGE);
}
}
//学生登录
public void studentlogin( String id, String password ) throws Exception {
boolean istrue = false;
StudentDao log = new StudentDao();
try {
istrue = log.LoginCheck(id, password);
stu = log.searchById(Integer.parseInt(id));
} catch (SQLException e1) {
e1.printStackTrace();
}
if(istrue) {
new StudentView().init();
dispose();
}else{
JOptionPane.showMessageDialog(null,"用户名或密码错误!","登陆失败",JOptionPane.ERROR_MESSAGE);
}
}
//主任登录
public void deanlogin( String id, String password ) throws Exception {
boolean istrue = false;
DeanDao log = new DeanDao();
try {
istrue = log.LoginCheck(id, password);
} catch (SQLException e1) {
e1.printStackTrace();
}
if(istrue) {
new DeanView().init();
dispose();
}else{
JOptionPane.showMessageDialog(null,"用户名或密码错误!","登陆失败",JOptionPane.ERROR_MESSAGE);
}
}
//教务登录
public void educaionallogin( String id, String password ) throws Exception {
boolean istrue = false;
EducaionalDao log = new EducaionalDao();
try {
istrue = log.LoginCheck(id, password);
} catch (SQLException e1) {
e1.printStackTrace();
}
if(istrue) {
new EducaionalView().init();
dispose();
}else{
JOptionPane.showMessageDialog(null,"用户名或密码错误!","登陆失败",JOptionPane.ERROR_MESSAGE);
}
}
/**
* Create the frame.
*/
public loginGUI() {
setTitle("教务管理系统");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(650, 350, 576, 377);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
//登录按钮
JButton btnNewButton = new JButton("登录");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
identify = (String) comboBox.getSelectedItem();
id = textField.getText();
password = String.valueOf(passwordField.getPassword());
switch (identify) {
case "教师":
if( checkNull(id, password) )
try {
teacherlogin(id, password);
} catch (Exception e1) {
e1.printStackTrace();
}
break;
case "学生":
if( checkNull(id, password) )
try {
studentlogin(id, password);
} catch (Exception e1) {
e1.printStackTrace();
}
break;
case "系主任":
if( checkNull(id, password) )
try {
deanlogin(id, password);
} catch (Exception e1) {
e1.printStackTrace();
}
break;
case "教务":
if( checkNull(id, password) )
try {
educaionallogin(id, password);
} catch (Exception e1) {
e1.printStackTrace();
}
break;
}
}
});
btnNewButton.setBounds(176, 247, 93, 35);
contentPane.add(btnNewButton);
textField = new JTextField();
textField.setFont(new Font("", Font.PLAIN, 16));
textField.setBounds(176, 129, 223, 35);
contentPane.add(textField);
textField.setColumns(10);
comboBox.setMaximumRowCount(4);
comboBox.setModel(new DefaultComboBoxModel<Object>(new String[] {"学生", "教师", "系主任", "教务"}));
comboBox.setSelectedIndex(0);
comboBox.setToolTipText("");
comboBox.setBounds(176, 91, 223, 28);
contentPane.add(comboBox);
passwordField = new JPasswordField();
passwordField.setFont(new Font("", Font.PLAIN, 16));
passwordField.setBounds(176, 182, 223, 35);
contentPane.add(passwordField);
JLabel lblQeqew = new JLabel("教务管理系统");
lblQeqew.setHorizontalAlignment(SwingConstants.CENTER);
lblQeqew.setFont(new Font("", Font.PLAIN, 36));
lblQeqew.setBounds(101, 27, 373, 46);
contentPane.add(lblQeqew);
JLabel lblNewLabel = new JLabel("用 户 名:");
lblNewLabel.setBounds(110, 140, 60, 15);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("密 码:");
lblNewLabel_1.setBounds(110, 190, 60, 15);
contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("身 份:");
lblNewLabel_2.setBounds(110, 98, 60, 15);
contentPane.add(lblNewLabel_2);
}
}
四、项目展示
选择身份登录界面
学生端
教师端
五、源码获取
因为页面与源码太多了,所以页面与源码只展示了一部分,完整源码已经打包了,点击下面蓝色链接获取!