开发工具eclipse,jdk1.8
技术:java swing
数据库:mysql5.7
学生选课系统功能:管理员、教师、学生三个角色
一、管理员功能:
1.登录、修改密码、退出系统
2.学生管理:添加、修改、删除、查询
3.班级管理:添加、修改、删除、查询
4.教师管理:添加、修改、删除、查询
5.课程管理:添加、修改、删除、查询
6.选课管理:修改选课、推选课程
7.签到管理和签到统计
签到管理:确认签到、添加缺席
签到统计:列表显示、柱状图显示、饼状图显示
8.帮助、关于
二、教师功能:
1.登录、修改密码、退出系统
2.学生管理:添加、修改、删除、查询
3.班级管理:添加、修改、删除、查询
4.教师管理:修改个人信息
5.课程管理:添加、修改、删除、查询
6.选课管理:修改选课、推选课程
7.签到管理和签到统计
签到管理:确认签到、添加缺席
签到统计:列表显示、柱状图显示、饼状图显示
8.帮助、关于
三、学生功能:
1.登录、修改密码、退出系统
2.学生管理:修改个人信息
3.选课管理:修改选课、推选课程
4.确认签到
5.帮助、关于
管理员截图:
教师截图:
学生截图:
package com.artisan.view;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import com.artisan.dao.ClassDao;
import com.artisan.dao.StudentDao;
import com.artisan.model.Student;
import com.artisan.model.StudentClass;
import com.artisan.util.StringUtil;
public class AddStudentFrm extends JInternalFrame {
private JTextField studentNameTextField;
private JPasswordField studentPasswordField;
private JComboBox studentClassComboBox;
private ButtonGroup sexButtonGroup;
private JRadioButton studentSexManRadioButton;
private JRadioButton studentSexFemalRadioButton;
private JRadioButton studentSexUnkonwRadioButton;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AddStudentFrm frame = new AddStudentFrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public AddStudentFrm() {
setClosable(true);
setIconifiable(true);
setTitle("\u6DFB\u52A0\u5B66\u751F");
setBounds(100, 100, 450, 300);
JLabel label = new JLabel("\u5B66\u751F\u59D3\u540D\uFF1A");
label.setIcon(new ImageIcon(AddStudentFrm.class.getResource("/images/\u5B66\u751F\u7BA1\u7406.png")));
label.setFont(new Font("微软雅黑", Font.PLAIN, 14));
studentNameTextField = new JTextField();
studentNameTextField.setColumns(10);
JLabel label_1 = new JLabel("\u6240\u5C5E\u73ED\u7EA7\uFF1A");
label_1.setIcon(new ImageIcon(AddStudentFrm.class.getResource("/images/\u73ED\u7EA7\u540D\u79F0.png")));
label_1.setFont(new Font("微软雅黑", Font.PLAIN, 14));
studentClassComboBox = new JComboBox();
studentClassComboBox.setModel(new DefaultComboBoxModel(new String[] {}));
JLabel label_2 = new JLabel("\u767B\u5F55\u5BC6\u7801\uFF1A");
label_2.setIcon(new ImageIcon(AddStudentFrm.class.getResource("/images/password.png")));
label_2.setFont(new Font("微软雅黑", Font.PLAIN, 14));
studentPasswordField = new JPasswordField();
JLabel label_3 = new JLabel("\u5B66\u751F\u6027\u522B\uFF1A");
label_3.setIcon(new ImageIcon(AddStudentFrm.class.getResource("/images/\u6027\u522B.png")));
label_3.setFont(new Font("微软雅黑", Font.PLAIN, 14));
studentSexManRadioButton = new JRadioButton("\u7537");
studentSexManRadioButton.setSelected(true);
studentSexFemalRadioButton = new JRadioButton("\u5973");
studentSexUnkonwRadioButton = new JRadioButton("\u4FDD\u5BC6");
sexButtonGroup = new ButtonGroup();
sexButtonGroup.add(studentSexManRadioButton);
sexButtonGroup.add(studentSexFemalRadioButton);
sexButtonGroup.add(studentSexUnkonwRadioButton);
JButton submitButton = new JButton("\u786E\u8BA4");
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
studentAddAct(ae);
}
});
submitButton.setIcon(new ImageIcon(AddStudentFrm.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(AddStudentFrm.class.getResource("/images/\u91CD\u7F6E.png")));
resetButton.setFont(new Font("微软雅黑", Font.PLAIN, 14));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(91)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label_2)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(studentPasswordField, GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label_1)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(studentClassComboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(studentNameTextField, GroupLayout.PREFERRED_SIZE, 151, GroupLayout.PREFERRED_SIZE)))
.addGap(92))
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
.addComponent(resetButton)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label_3)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(studentSexManRadioButton)
.addGap(10)
.addComponent(studentSexFemalRadioButton)
.addGap(10)
.addComponent(studentSexUnkonwRadioButton)))
.addContainerGap())))
.addGroup(groupLayout.createSequentialGroup()
.addGap(132)
.addComponent(submitButton)
.addContainerGap(221, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(30)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(label)
.addComponent(studentNameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(26)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(label_1)
.addComponent(studentClassComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(32)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(label_2)
.addComponent(studentPasswordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(29)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(label_3)
.addComponent(studentSexManRadioButton)
.addComponent(studentSexUnkonwRadioButton)
.addComponent(studentSexFemalRadioButton))
.addPreferredGap(ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(submitButton)
.addComponent(resetButton))
.addContainerGap())
);
getContentPane().setLayout(groupLayout);
setStudentClassInfo();
}
protected void resetValue(ActionEvent ae) {
// TODO Auto-generated method stub
studentNameTextField.setText("");
studentPasswordField.setText("");
studentClassComboBox.setSelectedIndex(0);
sexButtonGroup.clearSelection();
studentSexManRadioButton.setSelected(true);
}
protected void studentAddAct(ActionEvent ae) {
// TODO Auto-generated method stub
String studentName = studentNameTextField.getText().toString();
String studentPassword = studentPasswordField.getText().toString();
if(StringUtil.isEmpty(studentName)){
JOptionPane.showMessageDialog(this, "请填写学生姓名!");
return;
}
if(StringUtil.isEmpty(studentPassword)){
JOptionPane.showMessageDialog(this, "请填写密码!");
return;
}
StudentClass sc = (StudentClass)studentClassComboBox.getSelectedItem();
String sex = studentSexManRadioButton.isSelected() ? studentSexManRadioButton.getText() : (studentSexFemalRadioButton.isSelected() ? studentSexFemalRadioButton.getText() : studentSexUnkonwRadioButton.getText());
Student student = new Student();
student.setName(studentName);
student.setClassId(sc.getId());
student.setPassword(studentPassword);
student.setSex(sex);
StudentDao studentDao = new StudentDao();
if(studentDao.addStudent(student)){
JOptionPane.showMessageDialog(this, "添加成功!");
}else{
JOptionPane.showMessageDialog(this, "添加失败!");
}
resetValue(ae);
}
private void setStudentClassInfo(){
ClassDao classDao = new ClassDao();
List<StudentClass> classList = classDao.getClassList(new StudentClass());
for (StudentClass sc : classList) {
studentClassComboBox.addItem(sc);
}
classDao.closeDao();
}
}
package com.artisan.dao;
import com.artisan.model.Admin;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;public class AdminDao extends BaseDao {
/**
* 管理员登陆
*/
public Admin login(Admin admin){
String sql = "select * from s_admin where name=? and password=?";
Admin adminRst = null;
try {
PreparedStatement prst = con.prepareStatement(sql);//把sql语句传给数据库操作对象
prst.setString(1, admin.getName());
prst.setString(2, admin.getPassword());
ResultSet executeQuery = prst.executeQuery();
if(executeQuery.next()){
adminRst = new Admin();
adminRst.setId(executeQuery.getInt("id"));
adminRst.setName(executeQuery.getString("name"));
adminRst.setPassword(executeQuery.getString("password"));
adminRst.setCreateDate(executeQuery.getString("createDate"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return adminRst;
}
public String editPassword(Admin admin,String newPassword){
String sql = "select * from s_admin where id=? and password=?";
PreparedStatement prst = null;
int id = 0;
try {
prst = con.prepareStatement(sql);
prst.setInt(1, admin.getId());
prst.setString(2, admin.getPassword());
ResultSet executeQuery = prst.executeQuery();
if(!executeQuery.next()){
String retString = "旧密码错误!";
return retString;
}
id = executeQuery.getInt("id");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}//把sql语句传给数据库操作对象
String retString = "修改失败";
String sqlString = "update s_admin set password = ? where id = ?";
try {
prst = con.prepareStatement(sqlString);
prst.setString(1, newPassword);
prst.setInt(2, id);
int rst = prst.executeUpdate();
if(rst > 0){
retString = "密码修改成功!";
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//把sql语句传给数据库操作对象
return retString;
}
}