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("");
  }
}
相关文章
|
29天前
|
监控 Java API
如何使用Java语言快速开发一套智慧工地系统
使用Java开发智慧工地系统,采用Spring Cloud微服务架构和前后端分离设计,结合MySQL、MongoDB数据库及RESTful API,集成人脸识别、视频监控、设备与环境监测等功能模块,运用Spark/Flink处理大数据,ECharts/AntV G2实现数据可视化,确保系统安全与性能,采用敏捷开发模式,提供详尽文档与用户培训,支持云部署与容器化管理,快速构建高效、灵活的智慧工地解决方案。
|
20天前
|
设计模式 消息中间件 搜索推荐
Java 设计模式——观察者模式:从优衣库不使用新疆棉事件看系统的动态响应
【11月更文挑战第17天】观察者模式是一种行为设计模式,定义了一对多的依赖关系,使多个观察者对象能直接监听并响应某一主题对象的状态变化。本文介绍了观察者模式的基本概念、商业系统中的应用实例,如优衣库事件中各相关方的动态响应,以及模式的优势和实际系统设计中的应用建议,包括事件驱动架构和消息队列的使用。
|
1月前
|
Java Android开发
Eclipse Java 构建路径
Eclipse Java 构建路径
33 3
|
1月前
|
Java Android开发
Eclipse 创建 Java 项目
Eclipse 创建 Java 项目
39 4
|
1月前
|
Java Android开发
Eclipse 创建 Java 接口
Eclipse 创建 Java 接口
27 1
|
1月前
|
Java Android开发
Eclipse 创建 Java 包
Eclipse 创建 Java 包
31 1
|
1月前
|
运维 自然语言处理 供应链
Java云HIS医院管理系统源码 病案管理、医保业务、门诊、住院、电子病历编辑器
通过门诊的申请,或者直接住院登记,通过”护士工作站“分配患者,完成后,进入医生患者列表,医生对应开具”长期医嘱“和”临时医嘱“,并在电子病历中,记录病情。病人出院时,停止长期医嘱,开具出院医嘱。进入出院审核,审核医嘱与住院通过后,病人结清缴费,完成出院。
86 3
|
1月前
|
Java 数据库连接 数据库
深入探讨Java连接池技术如何通过复用数据库连接、减少连接建立和断开的开销,从而显著提升系统性能
在Java应用开发中,数据库操作常成为性能瓶颈。本文通过问题解答形式,深入探讨Java连接池技术如何通过复用数据库连接、减少连接建立和断开的开销,从而显著提升系统性能。文章介绍了连接池的优势、选择和使用方法,以及优化配置的技巧。
37 1
|
1月前
|
JavaScript Java 项目管理
Java毕设学习 基于SpringBoot + Vue 的医院管理系统 持续给大家寻找Java毕设学习项目(附源码)
基于SpringBoot + Vue的医院管理系统,涵盖医院、患者、挂号、药物、检查、病床、排班管理和数据分析等功能。开发工具为IDEA和HBuilder X,环境需配置jdk8、Node.js14、MySQL8。文末提供源码下载链接。
|
1月前
|
Java Android开发
Eclipse 创建 Java 类
Eclipse 创建 Java 类
26 0

推荐镜像

更多
下一篇
DataWorks