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

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

CourseManageInterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTable;
import com.sjsq.dao.CourseDao;
import com.sjsq.model.Course;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class CourseManageInterFrm extends javax.swing.JInternalFrame {
  private JTextField capacityTxt;
  private JTextField courseIdTxt;
  private JTextField courseNameTxt;
  private JTable courseTable;
  private JTextField courseTeacherTxt;
  private JTextField courseTimeTxt;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JLabel jLabel5;
  private JLabel jLabel6;
  private JLabel jLabel7;
  private JLabel jLabel8;
  private JLabel jLabel9;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JScrollPane jScrollPane1;
  private JButton jb_delete;
  private JButton jb_modify;
  private JButton jb_search;
  private JTextField numSelectedTxt;
  private JTextField s_courseNameTxt;
  private JTextField s_courseTeacherTxt;
  private JTextField s_courseTimeTxt;
  DbUtil dbUtil = new DbUtil();
  CourseDao courseDao = new CourseDao();
  private int NumSelected;
  public CourseManageInterFrm() {
    initComponents();
    this.setLocation(5, 20);
    this.fillTable(new Course());
  }
  private void resetValue() {
    this.courseIdTxt.setText("");
    this.courseNameTxt.setText("");
    this.courseTeacherTxt.setText("");
    this.courseTimeTxt.setText("");
    this.capacityTxt.setText("");
    this.numSelectedTxt.setText("");
  }
  private void fillTable(Course course) {
    DefaultTableModel dtm = (DefaultTableModel) courseTable.getModel();
    dtm.setRowCount(0);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      ResultSet rs = courseDao.courseList(con, course);
      while (rs.next()) {
        Vector v = new Vector();
        v.add(rs.getString("courseId"));
        v.add(rs.getString("courseName"));
        v.add(rs.getString("courseTime"));
        v.add(rs.getString("courseTeacher"));
        v.add(rs.getString("capacity"));
        v.add(rs.getString("numSelected"));
        dtm.addRow(v);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jPanel1 = new JPanel();
    jLabel1 = new JLabel();
    s_courseNameTxt = new JTextField();
    jLabel2 = new JLabel();
    s_courseTimeTxt = new JTextField();
    jLabel3 = new JLabel();
    s_courseTeacherTxt = new JTextField();
    jb_search = new JButton();
    jScrollPane1 = new JScrollPane();
    courseTable = new JTable();
    jPanel2 = new JPanel();
    courseIdTxt = new JTextField();
    jLabel4 = new JLabel();
    courseNameTxt = new JTextField();
    jLabel5 = new JLabel();
    courseTimeTxt = new JTextField();
    jLabel6 = new JLabel();
    courseTeacherTxt = new JTextField();
    jLabel7 = new JLabel();
    capacityTxt = new JTextField();
    jLabel8 = new JLabel();
    numSelectedTxt = new JTextField();
    jLabel9 = new JLabel();
    jb_modify = new JButton();
    jb_delete = new JButton();
    setClosable(true);
    setIconifiable(true);
    setTitle("课程信息修改");
    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("搜索条件"));
    jLabel1.setText("课程名称:");
    jLabel2.setText("上课时间:");
    jLabel3.setText("任课老师:");
    jb_search.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/search.png")));
    jb_search.setText("查询");
    jb_search.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_searchActionPerformed(evt);
      }
    });
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addGap(24, 24, 24).addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(s_courseNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 158,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(26, 26, 26).addComponent(jLabel3).addGap(18, 18, 18)
            .addComponent(s_courseTimeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 149,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(46, 46, 46).addComponent(jLabel2)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(s_courseTeacherTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 110,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
            .addComponent(jb_search).addGap(94, 94, 94)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(s_courseNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel1).addComponent(jb_search).addComponent(jLabel3)
                .addComponent(s_courseTimeTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel2).addComponent(s_courseTeacherTxt,
                    javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    courseTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {
    }, new String[] { "课程编号", "课程名称", "上课时间", "任课老师", "课程容量", "已选人数" }) {
      boolean[] canEdit = new boolean[] { false, false, false, false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    courseTable.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mousePressed(java.awt.event.MouseEvent evt) {
        courseTableMousePressed(evt);
      }
    });
    jScrollPane1.setViewportView(courseTable);
    jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("表单操作"));
    courseIdTxt.setEditable(false);
    jLabel4.setText("课程编号:");
    jLabel5.setText("课程名称:");
    jLabel6.setText("上课时间:");
    jLabel7.setText("任课老师:");
    jLabel8.setText("课程容量:");
    numSelectedTxt.setEditable(false);
    jLabel9.setText("已选人数:");
    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup().addGap(34, 34, 34).addGroup(jPanel2Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(courseTeacherTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 158,
                    javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45).addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(capacityTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 158,
                    javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46).addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(numSelectedTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 158,
                    javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(courseIdTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 158,
                    javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45).addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(courseNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 158,
                    javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46).addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(courseTimeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 158,
                    javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap(149, Short.MAX_VALUE)));
    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup().addGap(19, 19, 19)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(courseIdTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel4)
                .addComponent(courseTimeTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel6)
                .addComponent(courseNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel5))
            .addGap(32, 32, 32)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(courseTeacherTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel7)
                .addComponent(numSelectedTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel9)
                .addComponent(capacityTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel8))
            .addContainerGap(34, Short.MAX_VALUE)));
    jb_modify.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/modify.png")));
    jb_modify.setText("修改");
    jb_modify.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_modifyActionPerformed(evt);
      }
    });
    jb_delete.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/delete.png")));
    jb_delete.setText("删除");
    jb_delete.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_deleteActionPerformed(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()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                    Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 920, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
            .addGroup(layout.createSequentialGroup().addGap(330, 330, 330).addComponent(jb_modify)
                .addGap(78, 78, 78).addComponent(jb_delete)))
        .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(27, 27, 27)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jb_delete).addComponent(jb_modify))
            .addContainerGap(36, Short.MAX_VALUE)));
    pack();
  }
  private void jb_modifyActionPerformed(java.awt.event.ActionEvent evt) {
    String courseId = this.courseIdTxt.getText();
    if (StringUtil.isEmpty(courseId)) {
      JOptionPane.showMessageDialog(this, "请选择要修改的记录!");
      return;
    }
    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;
    }
    if (Integer.parseInt(capacity) < NumSelected) {
      JOptionPane.showMessageDialog(this, "课程容量不能小于已选课人数!");
      return;
    }
    Course course = new Course(Integer.parseInt(courseId), courseName, courseTime, courseTeacher,
        Integer.parseInt(capacity));
    Connection con = null;
    try {
      con = dbUtil.getCon();
      int modifyNum = courseDao.courseModify(con, course);
      if (modifyNum == 1) {
        JOptionPane.showMessageDialog(this, "修改成功!");
        this.resetValue();
        this.fillTable(new Course());
      } else {
        JOptionPane.showMessageDialog(this, "修改失败!");
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(this, "修改失败!");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void courseTableMousePressed(java.awt.event.MouseEvent evt) {
    // 获取选中的行
    int row = courseTable.getSelectedRow();
    this.courseIdTxt.setText((String) courseTable.getValueAt(row, 0));
    this.courseNameTxt.setText((String) courseTable.getValueAt(row, 1));
    this.courseTimeTxt.setText((String) courseTable.getValueAt(row, 2));
    this.courseTeacherTxt.setText((String) courseTable.getValueAt(row, 3));
    this.capacityTxt.setText((String) courseTable.getValueAt(row, 4));
    this.numSelectedTxt.setText((String) courseTable.getValueAt(row, 5));
    NumSelected = Integer.parseInt((String) courseTable.getValueAt(row, 5));
  }
  private void jb_searchActionPerformed(java.awt.event.ActionEvent evt) {
    String s_courseName = this.s_courseNameTxt.getText();
    String s_courseTime = this.s_courseTimeTxt.getText();
    String s_courseTeacher = this.s_courseTeacherTxt.getText();
    Course course = new Course(s_courseName, s_courseTime, s_courseTeacher);
    this.fillTable(course);
  }
  private void jb_deleteActionPerformed(java.awt.event.ActionEvent evt) {
    String courseId = this.courseIdTxt.getText();
    if (StringUtil.isEmpty(courseId)) {
      JOptionPane.showMessageDialog(this, "请选择要删除的记录!");
      return;
    }
    if (NumSelected > 0) {
      JOptionPane.showMessageDialog(this, "本课程已有人选,不能删除!");
      return;
    }
    int n = JOptionPane.showConfirmDialog(this, "确定要删除这条记录吗?");
    if (n == 0) {
      Connection con = null;
      try {
        con = dbUtil.getCon();
        int deleteNum = courseDao.courseDelete(con, courseId);
        if (deleteNum == 1) {
          JOptionPane.showMessageDialog(this, "删除成功!");
          this.resetValue();
          this.fillTable(new Course());
        } else {
          JOptionPane.showMessageDialog(this, "删除失败!");
        }
      } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "删除失败!");
      } finally {
        try {
          dbUtil.closeCon(con);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
}

CourseViewInterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.CourseDao;
import com.sjsq.model.Course;
import com.sjsq.util.DbUtil;
public class CourseViewInterFrm extends javax.swing.JInternalFrame {
  private JTable courseTable;
  private JScrollPane jScrollPane1;
  DbUtil dbUtil = new DbUtil();
  CourseDao courseDao = new CourseDao();
  public CourseViewInterFrm() {
    initComponents();
    this.setLocation(100, 50);
    this.fillTable(new Course());
  }
  private void fillTable(Course course) {
    DefaultTableModel dtm = (DefaultTableModel) courseTable.getModel();
    dtm.setRowCount(0);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      ResultSet rs = courseDao.courseList(con, course);
      while (rs.next()) {
        Vector v = new Vector();
        v.add(rs.getString("courseId"));
        v.add(rs.getString("courseName"));
        v.add(rs.getString("courseTime"));
        v.add(rs.getString("courseTeacher"));
        v.add(rs.getString("capacity"));
        v.add(rs.getString("numSelected"));
        dtm.addRow(v);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new JScrollPane();
    courseTable = new JTable();
    setClosable(true);
    setIconifiable(true);
    setTitle("查看选课情况");
    courseTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {
    }, new String[] { "课程编号", "课程名称", "上课时间", "任课老师", "课程容量", "已选人数" }) {
      boolean[] canEdit = new boolean[] { false, false, false, false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    jScrollPane1.setViewportView(courseTable);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 801, Short.MAX_VALUE)
            .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
            .addContainerGap()));
    pack();
  }
}

PasswordModifyInterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import com.sjsq.dao.StudentDao;
import com.sjsq.model.Student;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class PasswordModifyInterFrm extends javax.swing.JInternalFrame {
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JButton jb_modify;
  private JButton jb_reset;
  private JPasswordField newPasswordTxt;
  private JPasswordField oldPasswordTxt;
  private JPasswordField passwordConfirmTxt;
  DbUtil dbUtil = new DbUtil();
  StudentDao studentDao = new StudentDao();
  public PasswordModifyInterFrm() {
    initComponents();
    this.setLocation(200, 50);
  }
  private void initComponents() {
    jLabel1 = new JLabel();
    jLabel2 = new JLabel();
    jLabel3 = new JLabel();
    jb_modify = new JButton();
    jb_reset = new JButton();
    oldPasswordTxt = new JPasswordField();
    newPasswordTxt = new JPasswordField();
    passwordConfirmTxt = new JPasswordField();
    setClosable(true);
    setIconifiable(true);
    setTitle("修改密码");
    jLabel1.setText("原密码:");
    jLabel2.setText("新密码:");
    jLabel3.setText("再输入一次新密码:");
    jb_modify.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/modify.png")));
    jb_modify.setText("修改");
    jb_modify.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_modifyActionPerformed(evt);
      }
    });
    jb_reset.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/reset.png"))); // NOI18N
    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(88, 88, 88)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel3)
            .addComponent(jLabel2).addComponent(jLabel1).addComponent(jb_modify))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(newPasswordTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 152,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(passwordConfirmTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 152,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(oldPasswordTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 152,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jb_reset))
        .addContainerGap(105, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(28, 28, 28)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
            .addComponent(oldPasswordTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGap(28, 28, 28)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
            .addComponent(newPasswordTxt, 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(passwordConfirmTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jb_modify)
            .addComponent(jb_reset))
        .addGap(25, 25, 25)));
    pack();
  }
  private void jb_modifyActionPerformed(java.awt.event.ActionEvent evt) {
    String oldPassword = new String(this.oldPasswordTxt.getPassword());
    String newPassword = new String(this.newPasswordTxt.getPassword());
    String passwordConfirm = new String(this.passwordConfirmTxt.getPassword());
    if (StringUtil.isEmpty(oldPassword)) {
      JOptionPane.showMessageDialog(this, "原密码不能为空!");
      return;
    }
    if (StringUtil.isEmpty(newPassword)) {
      JOptionPane.showMessageDialog(this, "新密码不能为空!");
      return;
    }
    if (StringUtil.isEmpty(passwordConfirm)) {
      JOptionPane.showMessageDialog(this, "请再输入一遍新密码!");
      return;
    }
    String rightOldPassword = LogOnFrm.currentStudent.getSpassword();
    if (!oldPassword.equals(rightOldPassword)) {
      JOptionPane.showMessageDialog(this, "旧密码错误,请重新输入!");
      return;
    }
    if (!newPassword.equals(passwordConfirm)) {
      JOptionPane.showMessageDialog(this, "新密码不一致,请重新输入!");
      return;
    }
    Connection con = null;
    int currentSno = LogOnFrm.currentStudent.getSno();
    Student student = new Student(currentSno, newPassword);
    try {
      con = dbUtil.getCon();
      int modifyNum = studentDao.PasswordModify(con, student);
      if (modifyNum == 1) {
        JOptionPane.showMessageDialog(this, "修改成功!");
        this.resetValue();
      } else {
        JOptionPane.showMessageDialog(this, "修改失败!");
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(this, "修改失败!");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void resetValue() {
    this.oldPasswordTxt.setText("");
    this.newPasswordTxt.setText("");
    this.passwordConfirmTxt.setText("");
  }
  private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
    this.oldPasswordTxt.setText("");
    this.newPasswordTxt.setText("");
    this.passwordConfirmTxt.setText("");
  }
}

SelectCourseInterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.CourseDao;
import com.sjsq.dao.SelectionDao;
import com.sjsq.model.Course;
import com.sjsq.model.Selection;
import com.sjsq.util.DbUtil;
public class SelectCourseInterFrm extends javax.swing.JInternalFrame {
  private JTable courseTable;
  private JScrollPane jScrollPane1;
  private JButton jb_confirm;
  private JButton jb_underFull;
  DbUtil dbUtil = new DbUtil();
  CourseDao courseDao = new CourseDao();
  SelectionDao selectionDao = new SelectionDao();
  private int capacity;
  private int numSelected;
  private int courseId = -1;
  public SelectCourseInterFrm() {
    initComponents();
    this.setLocation(130, 50);
    this.fillTable(new Course());
  }
  private void fillTable(Course course) {
    DefaultTableModel dtm = (DefaultTableModel) courseTable.getModel();
    dtm.setRowCount(0);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      ResultSet rs = courseDao.courseList(con, course);
      while (rs.next()) {
        Vector v = new Vector();
        v.add(rs.getString("courseId"));
        v.add(rs.getString("courseName"));
        v.add(rs.getString("courseTime"));
        v.add(rs.getString("courseTeacher"));
        v.add(rs.getString("capacity"));
        v.add(rs.getString("numSelected"));
        dtm.addRow(v);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new JScrollPane();
    courseTable = new JTable();
    jb_underFull = new JButton();
    jb_confirm = new JButton();
    setClosable(true);
    setIconifiable(true);
    setTitle("课程选择");
    courseTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {
    }, new String[] { "课程编号", "课程名称", "上课时间", "任课老师", "课程容量", "已选人数" }) {
      boolean[] canEdit = new boolean[] { false, false, false, true, true, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    courseTable.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mousePressed(java.awt.event.MouseEvent evt) {
        courseTableMousePressed(evt);
      }
    });
    jScrollPane1.setViewportView(courseTable);
    jb_underFull.setText("只显示未选满课程");
    jb_underFull.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_underFullActionPerformed(evt);
      }
    });
    jb_confirm.setText("确认选择");
    jb_confirm.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_confirmActionPerformed(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()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane1,
                    javax.swing.GroupLayout.DEFAULT_SIZE, 578, Short.MAX_VALUE))
                .addGroup(layout.createSequentialGroup().addGap(134, 134, 134)
                    .addComponent(jb_underFull).addGap(98, 98, 98).addComponent(jb_confirm)))
            .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 319,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jb_underFull).addComponent(jb_confirm))
            .addContainerGap()));
    pack();
  }
  private void jb_underFullActionPerformed(java.awt.event.ActionEvent evt) {
    DefaultTableModel dtm = (DefaultTableModel) courseTable.getModel();
    dtm.setRowCount(0);
    Connection con = null;
    Course course = new Course();
    try {
      con = dbUtil.getCon();
      ResultSet rs = courseDao.UnderFullList(con, course);
      while (rs.next()) {
        Vector v = new Vector();
        v.add(rs.getString("courseId"));
        v.add(rs.getString("courseName"));
        v.add(rs.getString("courseTime"));
        v.add(rs.getString("courseTeacher"));
        v.add(rs.getString("capacity"));
        v.add(rs.getString("numSelected"));
        dtm.addRow(v);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void courseTableMousePressed(java.awt.event.MouseEvent evt) {
    int row = courseTable.getSelectedRow();
    courseId = Integer.parseInt((String) courseTable.getValueAt(row, 0));
    capacity = Integer.parseInt((String) courseTable.getValueAt(row, 4));
    numSelected = Integer.parseInt((String) courseTable.getValueAt(row, 5));
  }
  private void jb_confirmActionPerformed(java.awt.event.ActionEvent evt) {
    if (courseId == -1) {
      JOptionPane.showMessageDialog(this, "请选择一门课程!");
      return;
    }
    if (capacity == numSelected) {
      JOptionPane.showMessageDialog(this, "该课程已选满,请选择其他课程.");
      return;
    }
    int n = JOptionPane.showConfirmDialog(this, "确定要选择该门课程吗?");
    if (n == 0) {
      Connection con = null;
      int currentSno = LogOnFrm.currentStudent.getSno();
      Selection selection = new Selection(courseId, currentSno);
      try {
        con = dbUtil.getCon();
        int selectionNum = selectionDao.SelectionAdd(con, selection);
        int selectedNum = selectionDao.NumSelectedAdd(con, courseId);
        if (selectionNum == 1 && selectedNum == 1) {
          JOptionPane.showMessageDialog(this, "选课成功!");
          this.fillTable(new Course());
        } else {
          JOptionPane.showMessageDialog(this, "选课失败!");
        }
      } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "已选过该门课程!");
      } finally {
        try {
          dbUtil.closeCon(con);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
}

SelectedViewInterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.SelectionDao;
import com.sjsq.model.Course;
import com.sjsq.model.Selection;
import com.sjsq.util.DbUtil;
public class SelectedViewInterFrm extends javax.swing.JInternalFrame {
  private JTable courseTable;
  private JScrollPane jScrollPane1;
  private JButton jb_selectionCancel;
  DbUtil dbUtil = new DbUtil();
  SelectionDao selectionDao = new SelectionDao();
  private int courseId = -1;
  public SelectedViewInterFrm() {
    initComponents();
    this.setLocation(130, 50);
    this.fillTable(new Course());
  }
  private void fillTable(Course course) {
    DefaultTableModel dtm = (DefaultTableModel) courseTable.getModel();
    dtm.setRowCount(0);
    Connection con = null;
    int currentSno = LogOnFrm.currentStudent.getSno();
    try {
      con = dbUtil.getCon();
      ResultSet rs = selectionDao.SelectedList(con, currentSno);
      while (rs.next()) {
        Vector v = new Vector();
        v.add(rs.getString("courseId"));
        v.add(rs.getString("courseName"));
        v.add(rs.getString("courseTime"));
        v.add(rs.getString("courseTeacher"));
        dtm.addRow(v);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new JScrollPane();
    courseTable = new JTable();
    jb_selectionCancel = new JButton();
    setClosable(true);
    setIconifiable(true);
    setTitle("查看已选课程");
    courseTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {
    }, new String[] { "课程编号", "课程名称", "上课时间", "任课老师" }) {
      boolean[] canEdit = new boolean[] { false, false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    courseTable.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mousePressed(java.awt.event.MouseEvent evt) {
        courseTableMousePressed(evt);
      }
    });
    jScrollPane1.setViewportView(courseTable);
    jb_selectionCancel.setText("退选");
    jb_selectionCancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_selectionCancelActionPerformed(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()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane1,
                javax.swing.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE))
            .addGroup(
                layout.createSequentialGroup().addGap(272, 272, 272).addComponent(jb_selectionCancel)))
        .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 205,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18).addComponent(jb_selectionCancel).addContainerGap(14, Short.MAX_VALUE)));
    pack();
  }
  private void courseTableMousePressed(java.awt.event.MouseEvent evt) {
    int row = courseTable.getSelectedRow();
    courseId = Integer.parseInt((String) courseTable.getValueAt(row, 0));
  }
  private void jb_selectionCancelActionPerformed(
      java.awt.event.ActionEvent evt) {
    if (courseId == -1) {
      JOptionPane.showMessageDialog(this, "请选择一门课程!");
      return;
    }
    int n = JOptionPane.showConfirmDialog(this, "确定要退选该门课程吗?");
    if (n == 0) {
      Connection con = null;
      int currentSno = LogOnFrm.currentStudent.getSno();
      Selection selection = new Selection(courseId, currentSno);
      try {
        con = dbUtil.getCon();
        int selectionNum = selectionDao.SelectionCancel(con, selection);
        int selectedNum = selectionDao.NumSelectedMinus(con, courseId);
        if (selectionNum == 1 && selectedNum == 1) {
          JOptionPane.showMessageDialog(this, "退选成功!");
          this.fillTable(new Course());
        } else {
          JOptionPane.showMessageDialog(this, "退选失败!");
        }
      } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "退选失败!");
      } finally {
        try {
          dbUtil.closeCon(con);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
}

SelfInfoInterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.StudentDao;
import com.sjsq.model.Sinfo;
import com.sjsq.util.DbUtil;
public class SelfInfoInterFrm extends javax.swing.JInternalFrame {
  private JTable infoTable;
  private JScrollPane jScrollPane1;
  DbUtil dbUtil = new DbUtil();
  StudentDao studentDao = new StudentDao();
  public SelfInfoInterFrm() {
    initComponents();
    this.setLocation(170, 50);
    this.fillTable(new Sinfo());
  }
  private void fillTable(Sinfo sinfo) {
    DefaultTableModel dtm = (DefaultTableModel) infoTable.getModel();
    dtm.setRowCount(0);
    Connection con = null;
    int currentSno = LogOnFrm.currentStudent.getSno();
    sinfo = new Sinfo(currentSno);
    try {
      con = dbUtil.getCon();
      ResultSet rs = studentDao.StudentList(con, sinfo);
      while (rs.next()) {
        Vector v = new Vector();
        v.add(rs.getString("Sno"));
        v.add(rs.getString("Sname"));
        v.add(rs.getString("Ssex"));
        v.add(rs.getString("Smajor"));
        v.add(rs.getString("Stele"));
        dtm.addRow(v);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    infoTable = new javax.swing.JTable();
    setClosable(true);
    setIconifiable(true);
    setTitle("查看学籍信息");
    infoTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {
    }, new String[] { "学号", "姓名", "性别", "专业", "电话" }) {
      boolean[] canEdit = new boolean[] { false, false, false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    jScrollPane1.setViewportView(infoTable);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE)
            .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 51,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    pack();
  }
}

StudentPasswordInterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.StudentDao;
import com.sjsq.model.Student;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class StudentPasswordInterFrm extends javax.swing.JInternalFrame {
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JScrollPane jScrollPane1;
  private JButton jb_modify;
  private JButton jb_search;
  private JTable passwordTable;
  private JTextField passwordTxt;
  private JTextField s_snoTxt;
  private JTextField snoTxt;
  DbUtil dbUtil = new DbUtil();
  StudentDao studentDao = new StudentDao();
  public StudentPasswordInterFrm() {
    initComponents();
    this.setLocation(280, 50);
    this.fillTable(new Student());
  }
  private void fillTable(Student student) {
    DefaultTableModel dtm = (DefaultTableModel) passwordTable.getModel();
    dtm.setRowCount(0);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      ResultSet rs = studentDao.PasswordList(con, student);
      while (rs.next()) {
        Vector v = new Vector();
        v.add(rs.getString("Sno"));
        v.add(rs.getString("Spassword"));
        dtm.addRow(v);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new JScrollPane();
    passwordTable = new JTable();
    jPanel1 = new JPanel();
    jLabel1 = new JLabel();
    s_snoTxt = new JTextField();
    jb_search = new JButton();
    jPanel2 = new JPanel();
    snoTxt = new JTextField();
    jLabel2 = new JLabel();
    jLabel3 = new JLabel();
    passwordTxt = new JTextField();
    jb_modify = new JButton();
    setClosable(true);
    setIconifiable(true);
    setTitle("管理学生密码");
    passwordTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {
    }, new String[] { "学生学号", "密码" }) {
      boolean[] canEdit = new boolean[] { false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    passwordTable.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mousePressed(java.awt.event.MouseEvent evt) {
        passwordTableMousePressed(evt);
      }
    });
    jScrollPane1.setViewportView(passwordTable);
    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("搜索条件"));
    jLabel1.setText("学生学号:");
    jb_search.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/search.png")));
    jb_search.setText("查询");
    jb_search.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_searchActionPerformed(evt);
      }
    });
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
            jPanel1Layout.createSequentialGroup().addContainerGap(42, Short.MAX_VALUE).addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(s_snoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 103,
                    javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42).addComponent(jb_search).addGap(32, 32, 32)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(s_snoTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jb_search).addComponent(jLabel1))
            .addContainerGap(18, Short.MAX_VALUE)));
    jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("表单操作"));
    snoTxt.setEditable(false);
    jLabel2.setText("学生学号:");
    jLabel3.setText("学生密码:");
    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jLabel2)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(snoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 93,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
            .addComponent(jLabel3).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 122,
                javax.swing.GroupLayout.PREFERRED_SIZE)));
    jPanel2Layout
        .setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
                .addComponent(snoTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3).addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE)));
    jb_modify.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/modify.png")));
    jb_modify.setText("修改");
    jb_modify.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_modifyActionPerformed(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()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING,
                            javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 364,
                            Short.MAX_VALUE)))
                .addGroup(layout.createSequentialGroup().addGap(147, 147, 147).addComponent(jb_modify)))
            .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 169,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18).addComponent(jb_modify).addContainerGap(29, Short.MAX_VALUE)));
    pack();
  }
  private void jb_modifyActionPerformed(java.awt.event.ActionEvent evt) {
    String sno = this.snoTxt.getText();
    if (StringUtil.isEmpty(sno)) {
      JOptionPane.showMessageDialog(this, "请选择要修改的记录!");
      return;
    }
    String password = this.passwordTxt.getText();
    if (StringUtil.isEmpty(password)) {
      JOptionPane.showMessageDialog(this, "密码不能为空!");
      return;
    }
    Student student = new Student(Integer.parseInt(sno), password);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      int modifyNum = studentDao.PasswordModify(con, student);
      if (modifyNum == 1) {
        JOptionPane.showMessageDialog(this, "修改成功!");
        this.resetValue();
        this.fillTable(new Student());
      } else {
        JOptionPane.showMessageDialog(this, "修改失败!");
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(this, "修改失败!");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void resetValue() {
    this.snoTxt.setText("");
    this.passwordTxt.setText("");
  }
  private void passwordTableMousePressed(java.awt.event.MouseEvent evt) {
    int row = passwordTable.getSelectedRow();
    this.snoTxt.setText((String) passwordTable.getValueAt(row, 0));
    this.passwordTxt.setText((String) passwordTable.getValueAt(row, 1));
  }
  private void jb_searchActionPerformed(java.awt.event.ActionEvent evt) {
    String s_sno = this.s_snoTxt.getText();
    if (StringUtil.isEmpty(s_sno)) {
      s_sno = "-1";
    }
    Student student = new Student(Integer.parseInt(s_sno));
    this.fillTable(student);
  }
}

StudentViewInterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.StudentDao;
import com.sjsq.model.Sinfo;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class StudentViewInterFrm extends javax.swing.JInternalFrame {
  private JTextField SnameTxt;
  private JTextField SnoTxt;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JPanel jPanel1;
  private JScrollPane jScrollPane1;
  private JButton jb_search;
  private JTable studentTable;
  DbUtil dbUtil = new DbUtil();
  StudentDao studentDao = new StudentDao();
  public StudentViewInterFrm() {
    initComponents();
    this.setLocation(200, 50);
    this.fillTable(new Sinfo());
  }
  private void fillTable(Sinfo sinfo) {
    DefaultTableModel dtm = (DefaultTableModel) studentTable.getModel();
    dtm.setRowCount(0);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      ResultSet rs = studentDao.StudentList(con, sinfo);
      while (rs.next()) {
        Vector v = new Vector();
        v.add(rs.getString("Sno"));
        v.add(rs.getString("Sname"));
        v.add(rs.getString("Ssex"));
        v.add(rs.getString("Smajor"));
        v.add(rs.getString("Stele"));
        dtm.addRow(v);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new JScrollPane();
    studentTable = new JTable();
    jPanel1 = new JPanel();
    jLabel1 = new JLabel();
    SnoTxt = new JTextField();
    jLabel2 = new JLabel();
    SnameTxt = new JTextField();
    jb_search = new JButton();
    setClosable(true);
    setIconifiable(true);
    setTitle("查看学生资料");
    studentTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {
    }, new String[] { "学号", "姓名", "性别", "专业", "电话" }) {
      boolean[] canEdit = new boolean[] { false, false, false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    jScrollPane1.setViewportView(studentTable);
    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("搜索条件"));
    jLabel1.setText("学生学号:");
    jLabel2.setText("学生姓名:");
    jb_search.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/search.png")));
    jb_search.setText("查询");
    jb_search.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_searchActionPerformed(evt);
      }
    });
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addGap(78, 78, 78).addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(SnoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 104,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(69, 69, 69).addComponent(jLabel2)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(SnameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 96,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(56, 56, 56).addComponent(jb_search).addContainerGap(85, Short.MAX_VALUE)));
    jPanel1Layout
        .setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addGap(25, 25, 25).addGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
                .addComponent(SnoTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jb_search)
                .addComponent(SnameTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel2)).addContainerGap(38, Short.MAX_VALUE)));
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING,
                    javax.swing.GroupLayout.DEFAULT_SIZE, 685, Short.MAX_VALUE))
            .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 148,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(36, Short.MAX_VALUE)));
    pack();
  }
  private void jb_searchActionPerformed(java.awt.event.ActionEvent evt) {
    String sno = this.SnoTxt.getText();
    String sname = this.SnameTxt.getText();
    if (StringUtil.isEmpty(sno)) {
      sno = "-1";
    }
    Sinfo sinfo = new Sinfo(Integer.parseInt(sno), sname);
    this.fillTable(sinfo);
  }
}


四、其他


1.其他系统实现


JavaWeb系统系列实现

Java+JSP实现学生图书管理系统

Java+JSP实现学生信息管理系统

Java+JSP实现用户信息管理系统

Java+Servlet+JSP实现航空订票系统

Java+Servlet+JSP实现学生选课管理系统

Java+Servlet+JSP实现学生成绩管理系统

Java+Servlet+JSP实现宠物诊所管理系统

Java+SSM+Easyui实现网上考试系统

Java+Springboot+H-ui实现营销管理系统

Java+Springboot+Mybatis+Bootstrap实现网上商城系统


JavaSwing系统系列实现

Java+Swing实现斗地主游戏

Java+Swing实现图书管理系统

Java+Swing实现医院管理系统

Java+Swing实现仓库管理系统

Java+Swing实现考试管理系统

Java+Swing实现通讯录管理系统

Java+Swing实现停车场管理系统

Java+Swing实现学生信息管理系统

Java+Swing实现学生宿舍管理系统

Java+Swing实现学生选课管理系统

Java+Swing实现学生成绩管理系统

Java+Swing实现学校教材管理系统

Java+Swing实现学校教务管理系统

Java+Swing实现企业人事管理系统

Java+Swing实现电子相册管理系统

Java+Swing实现自助取款机(ATM)系统

Java+Swing实现超市管理系统-TXT存储信息

Java+Swing实现宠物商店管理系统-TXT存储信息


2.获取源码


点击以下链接获取源码,数据库文件在sql文件下面。

Java+Swing+Mysql学生选课管理系统源码


3.备注


如有侵权请联系我删除。


4.鸡汤


今日所行之事,是为明日大道所奠基,不慌张,缓缓来!


相关文章
|
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云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。文末提供源码下载链接。
|
7月前
|
Java Maven Android开发
在Eclipse里配置Maven插件
Maven是一款比较常用的Java开发拓展包,它相当于一个全自动jar包管理器,会导入用户开发时需要使用的相应jar包。使用Maven开发Java程序,可以极大提升开发者的开发效率。下面我就跟大家介绍一下如何在Eclipse里安装和配置Maven插件。
171 0
|
7月前
|
XML Java Maven
eclipse 、idea 安装activiti插件
eclipse 、idea 安装activiti插件
180 0
|
Java Android开发
eclipse安装SpringBoot插件的无敌办法
eclipse安装SpringBoot插件的无敌办法
151 0
|
Java Android开发 Spring
在 Eclipse 中安装 SpringTools 插件
在 Eclipse 中安装 SpringTools 插件
144 0

推荐镜像

更多
下一篇
DataWorks