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

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(“”);

}

}

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);

}

});

总结

就写到这了,也算是给这段时间的面试做一个总结,查漏补缺,祝自己好运吧,也希望正在求职或者打算跳槽的 程序员看到这个文章能有一点点帮助或收获,我就心满意足了。多思考,多问为什么。希望小伙伴们早点收到满意的offer! 越努力越幸运!

金九银十已经过了,就目前国内的面试模式来讲,在面试前积极的准备面试,复习整个 Java 知识体系将变得非常重要,可以很负责任的说一句,复习准备的是否充分,将直接影响你入职的成功率。但很多小伙伴却苦于没有合适的资料来回顾整个 Java 知识体系,或者有的小伙伴可能都不知道该从哪里开始复习。我偶然得到一份整理的资料,不论是从整个 Java 知识体系,还是从面试的角度来看,都是一份含技术量很高的资料。

三面蚂蚁核心金融部,Java开发岗(缓存+一致性哈希+分布式)

up(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);

}

});

总结

就写到这了,也算是给这段时间的面试做一个总结,查漏补缺,祝自己好运吧,也希望正在求职或者打算跳槽的 程序员看到这个文章能有一点点帮助或收获,我就心满意足了。多思考,多问为什么。希望小伙伴们早点收到满意的offer! 越努力越幸运!

金九银十已经过了,就目前国内的面试模式来讲,在面试前积极的准备面试,复习整个 Java 知识体系将变得非常重要,可以很负责任的说一句,复习准备的是否充分,将直接影响你入职的成功率。但很多小伙伴却苦于没有合适的资料来回顾整个 Java 知识体系,或者有的小伙伴可能都不知道该从哪里开始复习。我偶然得到一份整理的资料,不论是从整个 Java 知识体系,还是从面试的角度来看,都是一份含技术量很高的资料。

[外链图片转存中…(img-5oEsFsHI-1714119746610)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值