Eclipse+Java+Swing实现学生选课管理系统(上)

简介: Eclipse+Java+Swing实现学生选课管理系统

一、系统介绍


本系统实现了学生登录和管理员登录,学生实现选课,查看已选课程,修改密码,查看学生信息功能。管理员实现选课信息的增删改查,学生信息查询,学生密码修改功能。


二、系统展示


1.登录页面


20200906230720482.jpg


2.学生端-主页面


20200906230740669.jpg


3.学生端-课程选择


20200906230833229.jpg


4.学生端-查看已选课程


20200906230859836.jpg


5.学生端-修改密码


20200906230935324.jpg


6.学生端-学生信息查询


20200906231007185.jpg


7.管理员-主页面


20200906231044301.jpg


8.管理员-查看选课情况


20200906231118220.jpg


9.管理员-添加课程


20200906231208711.jpg


10.管理员-修改课程信息


20200906231242334.jpg


11.管理员-查询学生信息


20200906231326444.jpg


12.管理员-学生密码修改


20200906231402226.jpg


三、部分代码


Admin.java

package com.sjsq.model;
/**
 * Admin实体类
 * 
 * @author jakey
 * 
 * @author shuijianshiqing
 *
 * @date 2020-09-06 19:37
 *
 */
public class Admin {
  private int adminId;
  private String password;
  public Admin() {
    super();
  }
  public Admin(int adminId, String password) {
    super();
    this.adminId = adminId;
    this.password = password;
  }
  public int getAdminId() {
    return adminId;
  }
  public void setAdminId(int adminId) {
    this.adminId = adminId;
  }
  public String getPassword() {
    return password;
  }
  public void setPassword(String password) {
    this.password = password;
  }
}

Course.java

package com.sjsq.model;
public class Course {
  private int courseId = -1;
  private String courseName;
  private String courseTime;
  private String courseTeacher;
  private int capacity;
  private int numSelected;
  public Course() {
    super();
  }
  public Course(String courseName, String courseTime, String courseTeacher) {
    super();
    this.courseName = courseName;
    this.courseTime = courseTime;
    this.courseTeacher = courseTeacher;
  }
  public Course(int courseId, String courseName, String courseTime, String courseTeacher, int capacity) {
    super();
    this.courseId = courseId;
    this.courseName = courseName;
    this.courseTime = courseTime;
    this.courseTeacher = courseTeacher;
    this.capacity = capacity;
  }
  public Course(String courseName, String courseTime, String courseTeacher, int capacity) {
    super();
    this.courseName = courseName;
    this.courseTime = courseTime;
    this.courseTeacher = courseTeacher;
    this.capacity = capacity;
  }
  public int getCourseId() {
    return courseId;
  }
  public void setCourseId(int courseId) {
    this.courseId = courseId;
  }
  public String getCourseName() {
    return courseName;
  }
  public void setCourseName(String courseName) {
    this.courseName = courseName;
  }
  public String getCourseTime() {
    return courseTime;
  }
  public void setCourseTime(String courseTime) {
    this.courseTime = courseTime;
  }
  public String getCourseTeacher() {
    return courseTeacher;
  }
  public void setCourseTeacher(String courseTeacher) {
    this.courseTeacher = courseTeacher;
  }
  public int getCapacity() {
    return capacity;
  }
  public void setCapacity(int capacity) {
    this.capacity = capacity;
  }
  public int getNumSelected() {
    return numSelected;
  }
  public void setNumSelected(int numSelected) {
    this.numSelected = numSelected;
  }
}

Selection.java

package com.sjsq.model;
public class Selection {
  int selectId;
  int courseId = -1;
  int Sno;
  public Selection() {
    super();
  }
  public Selection(int courseId, int sno) {
    super();
    this.courseId = courseId;
    Sno = sno;
  }
  public int getSelectId() {
    return selectId;
  }
  public void setSelectId(int selectId) {
    this.selectId = selectId;
  }
  public int getCourseId() {
    return courseId;
  }
  public void setCourseId(int courseId) {
    this.courseId = courseId;
  }
  public int getSno() {
    return Sno;
  }
  public void setSno(int sno) {
    Sno = sno;
  }
}

Sinfo.java

package com.sjsq.model;
public class Sinfo {
  private int sno = -1;
  private String sname;
  private String ssex;
  private String smajor;
  private String stele;
  public Sinfo() {
    super();
  }
  public Sinfo(int sno) {
    super();
    this.sno = sno;
  }
  public Sinfo(int sno, String sname) {
    super();
    this.sno = sno;
    this.sname = sname;
  }
  public int getSno() {
    return sno;
  }
  public void setSno(int sno) {
    this.sno = sno;
  }
  public String getSname() {
    return sname;
  }
  public void setSname(String sname) {
    this.sname = sname;
  }
  public String getSsex() {
    return ssex;
  }
  public void setSsex(String ssex) {
    this.ssex = ssex;
  }
  public String getSmajor() {
    return smajor;
  }
  public void setSmajor(String smajor) {
    this.smajor = smajor;
  }
  public String getStele() {
    return stele;
  }
  public void setStele(String stele) {
    this.stele = stele;
  }
}

Student.java

package com.sjsq.model;
public class Student {
  private int Sno = -1;
  private String Spassword;
  public Student() {
    super();
  }
  public Student(int sno) {
    super();
    Sno = sno;
  }
  public Student(int sno, String spassword) {
    super();
    Sno = sno;
    Spassword = spassword;
  }
  public int getSno() {
    return Sno;
  }
  public void setSno(int sno) {
    Sno = sno;
  }
  public String getSpassword() {
    return Spassword;
  }
  public void setSpassword(String spassword) {
    Spassword = spassword;
  }
}

DbUtil.java

package com.sjsq.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DbUtil {
  private String dbUrl = "jdbc:mysql://localhost:3306/courseselection_management_swing?serverTimezone=Asia/Shanghai";
  private String dbUserName = "root";
  private String dbPassword = "admin";
  private String jdbcName = "com.mysql.cj.jdbc.Driver";
  /**
   * 获取数据库连接
   * 
   * @return
   * @throws Exception
   */
  public Connection getCon() throws Exception {
    Class.forName(jdbcName);
    Connection con = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
    return con;
  }
  public void closeCon(Connection con) throws Exception {
    if (con != null) {
      con.close();
    }
  }
  public static void main(String[] args) {
    DbUtil dbUtil = new DbUtil();
    try {
      dbUtil.getCon();
      System.out.println("数据库连接成功!");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

StringUtil.java

package com.sjsq.util;
public class StringUtil {
  public static boolean isEmpty(String str) {
    if ("".equals(str) || str == null) {
      return true;
    } else {
      return false;
    }
  }
  public static boolean isNotEmpty(String str) {
    if (!"".equals(str) && str != null) {
      return true;
    } else {
      return false;
    }
  }
}

LogOnDao.java

package com.sjsq.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.sjsq.model.Admin;
import com.sjsq.model.Student;
public class LogOnDao {
  /**
   * 登录验证
   * 
   * @param con
   * @param student
   * @return
   * @throws Exception
   */
  public Student login(Connection con, Student student) throws Exception {
    Student resultStu = null;
    String sql = "select * from t_slogon where Sno=? and Spassword=?";
    PreparedStatement pstmt = con.prepareStatement(sql);
    pstmt.setInt(1, student.getSno());
    pstmt.setString(2, student.getSpassword());
    ResultSet rs = pstmt.executeQuery();
    if (rs.next()) {
      resultStu = new Student();
      resultStu.setSno(rs.getInt("Sno"));
      resultStu.setSpassword(rs.getString("Spassword"));
    }
    return resultStu;
  }
  public Admin login(Connection con, Admin admin) throws Exception {
    Admin resultAdmin = null;
    String sql = "select * from t_adminlogon where adminId=? and password=?";
    PreparedStatement pstmt = con.prepareStatement(sql);
    pstmt.setInt(1, admin.getAdminId());
    pstmt.setString(2, admin.getPassword());
    ResultSet rs = pstmt.executeQuery();
    if (rs.next()) {
      resultAdmin = new Admin();
      resultAdmin.setAdminId(rs.getInt("adminId"));
      resultAdmin.setPassword(rs.getString("password"));
    }
    return resultAdmin;
  }
}

SelectionDao.java

package com.sjsq.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.sjsq.model.Selection;
public class SelectionDao {
  public int SelectionAdd(Connection con, Selection selection) throws Exception {
    String sql = "insert into t_selection value(null,?,?)";
    PreparedStatement pstmt = con.prepareStatement(sql);
    pstmt.setInt(1, selection.getCourseId());
    pstmt.setInt(2, selection.getSno());
    return pstmt.executeUpdate();
  }
  public int NumSelectedAdd(Connection con, int courseId) throws Exception {
    String sql = "update t_course set numSelected=numSelected+1 where courseId=?";
    PreparedStatement pstmt = con.prepareStatement(sql);
    pstmt.setInt(1, courseId);
    return pstmt.executeUpdate();
  }
  public ResultSet SelectedList(Connection con, int sno) throws Exception {
    String sql = "select  * from t_selection s,t_course c where s.Sno=? and s.courseId=c.courseId ";
    PreparedStatement pstmt = con.prepareStatement(sql);
    pstmt.setInt(1, sno);
    return pstmt.executeQuery();
  }
  public int SelectionCancel(Connection con, Selection selection) throws Exception {
    String sql = "delete from t_selection where courseId=? and Sno=?";
    PreparedStatement pstmt = con.prepareStatement(sql);
    pstmt.setInt(1, selection.getCourseId());
    pstmt.setInt(2, selection.getSno());
    return pstmt.executeUpdate();
  }
  public int NumSelectedMinus(Connection con, int courseId) throws Exception {
    String sql = "update t_course set numSelected=numSelected-1 where courseId=?";
    PreparedStatement pstmt = con.prepareStatement(sql);
    pstmt.setInt(1, courseId);
    return pstmt.executeUpdate();
  }
}

StudentDao.java

package com.sjsq.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.sjsq.model.Sinfo;
import com.sjsq.model.Student;
import com.sjsq.util.StringUtil;
public class StudentDao {
  public ResultSet StudentList(Connection con, Sinfo sinfo) throws SQLException {
    StringBuffer sb = new StringBuffer("select * from t_sinfo ");
    if (sinfo.getSno() != -1) {
      sb.append(" and Sno=" + sinfo.getSno());
    }
    if (StringUtil.isNotEmpty(sinfo.getSname())) {
      sb.append(" and Sname like '%" + sinfo.getSname() + "%'");
    }
    PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
    return pstmt.executeQuery();
  }
  public ResultSet PasswordList(Connection con, Student student) throws SQLException {
    StringBuffer sb = new StringBuffer("select * from t_slogon ");
    if (student.getSno() != -1) {
      sb.append("where Sno=" + student.getSno());
    }
    PreparedStatement pstmt = con.prepareStatement(sb.toString());
    return pstmt.executeQuery();
  }
  public int PasswordModify(Connection con, Student student) throws Exception {
    String sql = "update t_slogon set Spassword=? where Sno=? ";
    PreparedStatement pstmt = con.prepareStatement(sql);
    pstmt.setString(1, student.getSpassword());
    pstmt.setInt(2, student.getSno());
    return pstmt.executeUpdate();
  }
}

LogOnFrm.java

package com.sjsq.view;
import java.awt.Font;
import java.sql.Connection;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.UIManager;
import com.sjsq.dao.LogOnDao;
import com.sjsq.model.Admin;
import com.sjsq.model.Student;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class LogOnFrm extends javax.swing.JFrame {
  private ButtonGroup buttonGroup1;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JButton jb_logOn;
  private JButton jb_reset;
  private JRadioButton jrb_admin;
  private JRadioButton jrb_student;
  private JPasswordField passwordTxt;
  private JFormattedTextField userNameTxt;
  DbUtil dbUtil = new DbUtil();
  LogOnDao logOnDao = new LogOnDao();
  public static Student currentStudent;
  public LogOnFrm() {
    Font font = new Font("Dialog", Font.PLAIN, 12);
    java.util.Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
      Object key = keys.nextElement();
      Object value = UIManager.get(key);
      if (value instanceof javax.swing.plaf.FontUIResource) {
        UIManager.put(key, font);
      }
    }
    initComponents();
    this.setLocationRelativeTo(null);
    this.jrb_student.setSelected(true);
  }
  private void initComponents() {
    buttonGroup1 = new ButtonGroup();
    jLabel1 = new JLabel();
    jLabel2 = new JLabel();
    userNameTxt = new JFormattedTextField();
    jLabel3 = new JLabel();
    jrb_student = new JRadioButton();
    jrb_admin = new JRadioButton();
    jb_logOn = new JButton();
    jb_reset = new JButton();
    passwordTxt = new JPasswordField();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("用户登录页面");
    setResizable(false);
    jLabel1.setFont(new java.awt.Font("隶书", 1, 24));
    jLabel1.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/sys.png")));
    jLabel1.setText("学生选课系统");
    jLabel2.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/userName.png")));
    jLabel2.setText("账号");
    jLabel3.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/password.png")));
    jLabel3.setText("密码");
    buttonGroup1.add(jrb_student);
    jrb_student.setText("学生");
    jrb_student.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/student.png")));
    buttonGroup1.add(jrb_admin);
    jrb_admin.setText("管理员");
    jrb_admin.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/admin.png")));
    jb_logOn.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/login.png")));
    jb_logOn.setText("登录");
    jb_logOn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_logOnActionPerformed(evt);
      }
    });
    jb_reset.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/reset.png")));
    jb_reset.setText("重置");
    jb_reset.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_resetActionPerformed(evt);
      }
    });
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(106, 106, 106)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel1)
            .addGroup(layout.createSequentialGroup().addGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                    layout.createSequentialGroup().addComponent(jLabel3).addGap(33, 33, 33))
                .addGroup(layout.createSequentialGroup().addComponent(jLabel2).addGap(33, 33, 33)))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(passwordTxt, 0, 0, Short.MAX_VALUE)
                    .addComponent(userNameTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 135,
                        Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                        layout.createSequentialGroup().addGroup(layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jb_logOn).addComponent(jrb_student))
                            .addGroup(layout
                                .createParallelGroup(
                                    javax.swing.GroupLayout.Alignment.LEADING,
                                    false)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(29, 29, 29).addComponent(jb_reset))
                                .addGroup(layout.createSequentialGroup()
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jrb_admin,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)))))))
        .addContainerGap(143, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap(77, Short.MAX_VALUE).addComponent(jLabel1).addGap(39, 39, 39)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel2).addComponent(userNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3).addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jrb_student).addComponent(jrb_admin))
            .addGap(32, 32, 32)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jb_reset).addComponent(jb_logOn))
            .addGap(58, 58, 58)));
    pack();
  }
  private void jb_logOnActionPerformed(java.awt.event.ActionEvent evt) {
    String userName = userNameTxt.getText();
    String password = new String(passwordTxt.getPassword());
    if (StringUtil.isEmpty(userName)) {
      JOptionPane.showMessageDialog(this, "账号不能为空!");
      return;
    }
    if (StringUtil.isEmpty(password)) {
      JOptionPane.showMessageDialog(this, "密码不能为空!");
      return;
    }
    Connection con = null;
    if (this.jrb_student.isSelected()) {
      Student student = new Student(Integer.parseInt(userName), password);
      try {
        con = dbUtil.getCon();
        currentStudent = logOnDao.login(con, student);
        if (currentStudent != null) {
          this.dispose();
          new MainFrm_student().setVisible(true);
        } else {
          JOptionPane.showMessageDialog(this, "用户名或密码错误!");
        }
      } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "登录失败!");
      } finally {
        try {
          dbUtil.closeCon(con);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    } else if (this.jrb_admin.isSelected()) {
      Admin admin = new Admin(Integer.parseInt(userName), password);
      try {
        con = dbUtil.getCon();
        Admin currentAdmin = logOnDao.login(con, admin);
        if (currentAdmin != null) {
          this.dispose();
          new MainFrm_admin().setVisible(true);
        } else {
          JOptionPane.showMessageDialog(this, "用户名或密码错误!");
        }
      } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "登录失败!");
      } finally {
        try {
          dbUtil.closeCon(con);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
  private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
    this.resetValue();
  }
  private void resetValue() {
    this.userNameTxt.setText("");
    this.passwordTxt.setText("");
    this.jrb_student.setSelected(true);
  }
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        new LogOnFrm().setVisible(true);
      }
    });
  }
}

CourseAddInterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import com.sjsq.dao.CourseDao;
import com.sjsq.model.Course;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class CourseAddInterFrm extends javax.swing.JInternalFrame {
  private JTextField capacityTxt;
  private JTextField courseNameTxt;
  private JTextField courseTeacherTxt;
  private JTextField courseTimeTxt;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JButton jb_add;
  private JButton jb_reset;
  DbUtil dbUtil = new DbUtil();
  CourseDao coursedao = new CourseDao();
  public CourseAddInterFrm() {
    initComponents();
    this.setLocation(200, 50);
  }
  private void initComponents() {
    jLabel1 = new JLabel();
    jLabel2 = new JLabel();
    courseTimeTxt = new JTextField();
    jLabel3 = new JLabel();
    jLabel4 = new JLabel();
    courseNameTxt = new JTextField();
    courseTeacherTxt = new JTextField();
    capacityTxt = new JTextField();
    jb_add = new JButton();
    jb_reset = new JButton();
    setClosable(true);
    setIconifiable(true);
    setTitle("添加课程");
    jLabel1.setText("课程名称:");
    jLabel2.setText("上课时间:");
    jLabel3.setText("任课老师:");
    jLabel4.setText("课程容量:");
    jb_add.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/add.png")));
    jb_add.setText("添加");
    jb_add.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_addActionPerformed(evt);
      }
    });
    jb_reset.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/reset.png")));
    jb_reset.setText("重置");
    jb_reset.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_resetActionPerformed(evt);
      }
    });
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(41, 41, 41)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(courseNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 144,
                    javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(60, 60, 60).addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
                    courseTimeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 144,
                    javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup().addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(courseTeacherTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                            144, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jb_add))
                .addGap(60, 60, 60)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup().addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(capacityTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 144,
                            javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jb_reset))))
        .addContainerGap(44, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addGap(46, 46, 46)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1).addComponent(jLabel2)
                .addComponent(courseTimeTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(courseNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3).addComponent(jLabel4)
                .addComponent(courseTeacherTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(capacityTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jb_reset).addComponent(jb_add))
            .addGap(20, 20, 20)));
    pack();
  }
  private void jb_addActionPerformed(java.awt.event.ActionEvent evt) {
    String courseName = this.courseNameTxt.getText();
    String courseTime = this.courseTimeTxt.getText();
    String courseTeacher = this.courseTeacherTxt.getText();
    String capacity = this.capacityTxt.getText();
    if (StringUtil.isEmpty(courseName)) {
      JOptionPane.showMessageDialog(this, "课程名称不能为空!");
      return;
    }
    if (StringUtil.isEmpty(courseTime)) {
      JOptionPane.showMessageDialog(this, "上课时间不能为空!");
      return;
    }
    if (StringUtil.isEmpty(courseTeacher)) {
      JOptionPane.showMessageDialog(this, "任课老师不能为空!");
      return;
    }
    if (StringUtil.isEmpty(capacity)) {
      JOptionPane.showMessageDialog(this, "课程容量不能为空!");
      return;
    }
    Course course = new Course(courseName, courseTime, courseTeacher, Integer.parseInt(capacity));
    Connection con = null;
    try {
      con = dbUtil.getCon();
      int n = coursedao.courseAdd(con, course);
      if (n == 1) {
        JOptionPane.showMessageDialog(this, "课程添加成功!");
        this.resetValue();
      } else {
        JOptionPane.showMessageDialog(this, "课程添加失败!");
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(this, "课程添加失败!");
    }
  }
  private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
    this.resetValue();
  }
  private void resetValue() {
    this.courseNameTxt.setText("");
    this.courseTeacherTxt.setText("");
    this.courseTimeTxt.setText("");
    this.capacityTxt.setText("");
  }
}
相关文章
|
4天前
|
Java
学院管理系统【JSP+Servlet+JavaBean】(Java课设)
学院管理系统【JSP+Servlet+JavaBean】(Java课设)
20 3
学院管理系统【JSP+Servlet+JavaBean】(Java课设)
|
4天前
|
Java
学校教师管理系统【JSP+Servlet+JavaBean】(Java课设)
学校教师管理系统【JSP+Servlet+JavaBean】(Java课设)
17 2
|
4天前
|
Java 关系型数据库 MySQL
java+B/S架构医院绩效考核管理系统源码 医院绩效管理系统4大特点
医院绩效考核管理系统,采用多维度综合绩效考核的形式,针对院内实际情况分别对工作量、KPI指标、科研、教学、管理等进行全面考核。医院可结合实际需求,对考核方案中各维度进行灵活配置,对各维度的权重、衡量标准、数据统计方式进行自定义维护。
13 0
|
4天前
|
监控 前端开发 Java
Java公立医院绩效考核管理系统 医院绩效考核系统的优势有哪些? 
医院绩效管理系统解决方案紧扣新医改形势下医院绩效管理的要求,以“工作量为基础的考核方案”为核心思想,结合患者满意度、服务质量、技术难度、工作效率、医德医风等管理发展目标的考核体系,形成医院的内部绩效考核与分配机制,通过信息化手段为绩效考评管理人员实施医院绩效考评工作提供了有效工具,扩展了信息管理范围,增加了信息分析的广度与深度。这不仅使绩效评价工作更加科学化、规范化和自动化,而且从根本上改变了绩效评估工作方式,实现了绩效评价数据网络化采集,评价结果透明化管理,奖金分配数据自动化生成,极大地提高了绩效评估的全面性、准确性、时效性、公正性。从而推进医院绩效管理的专业化、规范化和精细化管理,充分发挥
14 0
|
4天前
|
Java
学校人员管理系统【JSP+Servlet+JavaBean】(Java课设)
学校人员管理系统【JSP+Servlet+JavaBean】(Java课设)
13 2
|
4天前
|
Java
个人信息管理系统【JSP+Servlet+JavaBean】(Java课设)
个人信息管理系统【JSP+Servlet+JavaBean】(Java课设)
10 0
|
4天前
|
监控 前端开发 Java
Java基于B/S医院绩效考核管理平台系统源码 医院智慧绩效管理系统源码
医院绩效考核系统是一个关键的管理工具,旨在评估和优化医院内部各部门、科室和员工的绩效。一个有效的绩效考核系统不仅能帮助医院实现其战略目标,还能提升医疗服务质量,增强患者满意度,并促进员工的专业成长
20 0
|
4天前
|
小程序 Java 关系型数据库
Java毕设之社区生活超市管理系统
Java毕设之社区生活超市管理系统
20 1
|
4天前
|
小程序 Java 关系型数据库
Java毕设之人事管理系统
Java毕设之人事管理系统
17 3
|
4天前
|
小程序 Java PHP
Java毕设之人才公寓管理系统
Java毕设之人才公寓管理系统
15 2

推荐镜像

更多