开发工具eclipse,jdk1.8
技术:java swing
数据库:mysql5.7
学生选课系统功能:管理员、教师、学生三个角色
一、管理员功能:
1.登录、修改密码、退出系统
2.学生管理:添加、修改、删除、查询
3.班级管理:添加、修改、删除、查询
4.教师管理:添加、修改、删除、查询
5.课程管理:添加、修改、删除、查询
6.选课管理:修改选课、推选课程
7.帮助、关于
二、教师功能:
1.登录、修改密码、退出系统
2.学生管理:添加、修改、删除、查询
3.班级管理:添加、修改、删除、查询
4.教师管理:修改个人信息
5.课程管理:添加、修改、删除、查询
6.选课管理:修改选课、推选课程
7.帮助、关于
三、学生功能:
1.登录、修改密码、退出系统
2.学生管理:修改个人信息
3.选课管理:修改选课、推选课程
4.帮助、关于
管理员截图:
教师截图:
学生截图:
package com.artisan.view;
import java.awt.EventQueue;
import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.JOptionPane;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextArea;
import javax.swing.JButton;
import com.artisan.dao.ClassDao;
import com.artisan.model.StudentClass;
import com.artisan.util.StringUtil;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class AddStudentClassFrm extends JInternalFrame {
private JTextField classNameTextField;
private JTextArea classInfotextArea;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AddStudentClassFrm frame = new AddStudentClassFrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public AddStudentClassFrm() {
setClosable(true);
setIconifiable(true);
setTitle("\u6DFB\u52A0\u73ED\u7EA7\u4FE1\u606F");
setBounds(100, 100, 450, 300);
JLabel label = new JLabel("\u73ED\u7EA7\u540D\u79F0\uFF1A");
label.setIcon(new ImageIcon(AddStudentClassFrm.class.getResource("/images/\u73ED\u7EA7\u540D\u79F0.png")));
label.setFont(new Font("微软雅黑", Font.PLAIN, 14));
classNameTextField = new JTextField();
classNameTextField.setColumns(10);
JLabel label_1 = new JLabel("\u73ED\u7EA7\u4FE1\u606F\uFF1A");
label_1.setIcon(new ImageIcon(AddStudentClassFrm.class.getResource("/images/\u73ED\u7EA7\u4ECB\u7ECD.png")));
label_1.setFont(new Font("微软雅黑", Font.PLAIN, 14));
classInfotextArea = new JTextArea();
JButton submitButton = new JButton("\u63D0\u4EA4");
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
submitClass(ae);
}
});
submitButton.setIcon(new ImageIcon(AddStudentClassFrm.class.getResource("/images/\u786E\u8BA4.png")));
submitButton.setFont(new Font("微软雅黑", Font.PLAIN, 14));
JButton restButton = new JButton("\u91CD\u7F6E");
restButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
resetValue(e);
}
});
restButton.setIcon(new ImageIcon(AddStudentClassFrm.class.getResource("/images/\u91CD\u7F6E.png")));
restButton.setFont(new Font("微软雅黑", Font.PLAIN, 14));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(submitButton)
.addGap(72)
.addComponent(restButton))
.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup()
.addGap(73)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label_1)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(classInfotextArea))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(classNameTextField, GroupLayout.PREFERRED_SIZE, 173, GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(88, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(32)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(label)
.addComponent(classNameTextField, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE))
.addGap(39)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(label_1)
.addComponent(classInfotextArea, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(restButton)
.addComponent(submitButton))
.addGap(18))
);
getContentPane().setLayout(groupLayout);
}
protected void submitClass(ActionEvent ae) {
// TODO Auto-generated method stub
String className = classNameTextField.getText().toString();
String classInfo = classInfotextArea.getText().toString();
if(StringUtil.isEmpty(className)){
JOptionPane.showMessageDialog(this, "班级名称不能为空!");
return;
}
StudentClass scl = new StudentClass();
scl.setName(className);
scl.setInfo(classInfo);
ClassDao classDao = new ClassDao();
if(classDao.addClass(scl)){
JOptionPane.showMessageDialog(this, "班级添加成功!");
}else{
JOptionPane.showMessageDialog(this, "班级添加失败!");
}
classDao.closeDao();
resetValue(ae);
}
protected void resetValue(ActionEvent e) {
// TODO Auto-generated method stub
classNameTextField.setText("");
classInfotextArea.setText("");
}
}
package com.artisan.view;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import com.artisan.dao.AdminDao;
import com.artisan.dao.StudentDao;
import com.artisan.dao.TeacherDao;
import com.artisan.model.Admin;
import com.artisan.model.Student;
import com.artisan.model.Teacher;
import com.artisan.util.StringUtil;
public class EditPasswordFrm extends JInternalFrame {
private JPanel contentPane;
private JPasswordField oldPasswordTextField;
private JPasswordField newPasswordTextField;
private JPasswordField confirmPasswordTextField;
private JLabel currentUserLabel;
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// EditPasswordFrm frame = new EditPasswordFrm();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
/**
* Create the frame.
*/
public EditPasswordFrm() {
setTitle("\u4FEE\u6539\u5BC6\u7801");
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
setClosable(true);
setIconifiable(true);
JLabel label = new JLabel("\u539F\u5BC6\u7801\uFF1A");
label.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/password.png")));
label.setFont(new Font("微软雅黑", Font.PLAIN, 14));
oldPasswordTextField = new JPasswordField();
oldPasswordTextField.setColumns(10);
JLabel label_1 = new JLabel("\u65B0\u5BC6\u7801\uFF1A");
label_1.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u4FEE\u6539\u5BC6\u7801.png")));
label_1.setFont(new Font("微软雅黑", Font.PLAIN, 14));
newPasswordTextField = new JPasswordField();
newPasswordTextField.setColumns(10);
JLabel label_2 = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A");
label_2.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u4FEE\u6539\u5BC6\u7801.png")));
label_2.setFont(new Font("微软雅黑", Font.PLAIN, 14));
confirmPasswordTextField = new JPasswordField();
confirmPasswordTextField.setColumns(10);
JButton submitButton = new JButton("\u786E\u8BA4");
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
submitEdit(e);
}
});
submitButton.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u786E\u8BA4.png")));
submitButton.setFont(new Font("微软雅黑", Font.PLAIN, 14));
JButton resetButton = new JButton("\u91CD\u7F6E");
resetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
resetValue(ae);
}
});
resetButton.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u91CD\u7F6E.png")));
resetButton.setFont(new Font("微软雅黑", Font.PLAIN, 14));
JLabel label_3 = new JLabel("\u5F53\u524D\u7528\u6237\uFF1A");
label_3.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u7528\u6237\u540D.png")));
label_3.setFont(new Font("微软雅黑", Font.PLAIN, 14));
currentUserLabel = new JLabel("");
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(86)
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(submitButton)
.addGap(61)
.addComponent(resetButton))
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(label_2)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(confirmPasswordTextField, 167, 167, 167))
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(label_1)
.addComponent(label))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(newPasswordTextField)
.addComponent(oldPasswordTextField, GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(label_3)
.addGap(18)
.addComponent(currentUserLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap(77, Short.MAX_VALUE))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(24)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(label_3)
.addComponent(currentUserLabel))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(label)
.addComponent(oldPasswordTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(32)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(label_1)
.addComponent(newPasswordTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(28)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(label_2)
.addComponent(confirmPasswordTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(resetButton)
.addComponent(submitButton))
.addContainerGap())
);
contentPane.setLayout(gl_contentPane);
if("系统管理员".equals(MainFrm.userType.getName())){
Admin admin = (Admin)MainFrm.userObject;
currentUserLabel.setText("【系统管理员】" + admin.getName());
}else if("学生".equals(MainFrm.userType.getName())){
Student student = (Student)MainFrm.userObject;
currentUserLabel.setText("【学生】" + student.getName());
}else{
Teacher teacher = (Teacher)MainFrm.userObject;
currentUserLabel.setText("【学生】" + teacher.getName());
}
}
protected void submitEdit(ActionEvent e) {
// TODO Auto-generated method stub
String oldPassword = oldPasswordTextField.getText().toString();
String newPassword = newPasswordTextField.getText().toString();
String conformPassword = confirmPasswordTextField.getText().toString();
if(StringUtil.isEmpty(oldPassword)){
JOptionPane.showMessageDialog(this, "请填写旧密码!");
return;
}
if(StringUtil.isEmpty(newPassword)){
JOptionPane.showMessageDialog(this, "请填写新密码!");
return;
}
if(StringUtil.isEmpty(conformPassword)){
JOptionPane.showMessageDialog(this, "请确认新密码!");
return;
}
if(!newPassword.equals(conformPassword)){
JOptionPane.showMessageDialog(this, "两次密码输入不一致!");
return;
}
if("系统管理员".equals(MainFrm.userType.getName())){
AdminDao adminDao = new AdminDao();
Admin adminTmp = new Admin();
Admin admin = (Admin)MainFrm.userObject;
adminTmp.setName(admin.getName());
adminTmp.setId(admin.getId());
adminTmp.setPassword(oldPassword);
JOptionPane.showMessageDialog(this, adminDao.editPassword(adminTmp, newPassword));
adminDao.closeDao();
return;
}
if("学生".equals(MainFrm.userType.getName())){
StudentDao studentDao = new StudentDao();
Student studentTmp = new Student();
Student student = (Student)MainFrm.userObject;
studentTmp.setName(student.getName());
studentTmp.setPassword(oldPassword);
studentTmp.setId(student.getId());
JOptionPane.showMessageDialog(this, studentDao.editPassword(studentTmp, newPassword));
studentDao.closeDao();
return;
}
if("教师".equals(MainFrm.userType.getName())){
TeacherDao teacherDao = new TeacherDao();
Teacher teacherTmp = new Teacher();
Teacher teacher = (Teacher)MainFrm.userObject;
teacherTmp.setName(teacher.getName());
teacherTmp.setPassword(oldPassword);
teacherTmp.setId(teacher.getId());
JOptionPane.showMessageDialog(this, teacherDao.editPassword(teacherTmp, newPassword));
teacherDao.closeDao();
return;
}
}
protected void resetValue(ActionEvent ae) {
// TODO Auto-generated method stub
oldPasswordTextField.setText("");
newPasswordTextField.setText("");
confirmPasswordTextField.setText("");
}
}