本系统实现了学生登录和管理员登录,学生实现选课,查看已选课程,修改密码,查看学生信息功能。管理员实现选课信息的增删改查,学生信息查询,学生密码修改功能。
package com.sjsq.model;
/** * Admin实体类 * * @author jakey * * @author shuijianshiqing * * @date 2020-09-06 19:37 * */
public class Admin {
private int adminId;
private String password;
public Admin() {
super();
}
public Admin(int adminId, String password) {
super();
this.adminId = adminId;
this.password = password;
}
public int getAdminId() {
return adminId;
}
public void setAdminId(int adminId) {
this.adminId = adminId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.sjsq.model;
public class Course {
private int courseId = -1;
private String courseName;
private String courseTime;
private String courseTeacher;
private int capacity;
private int numSelected;
public Course() {
super();
}
public Course(String courseName, String courseTime, String courseTeacher) {
super();
this.courseName = courseName;
this.courseTime = courseTime;
this.courseTeacher = courseTeacher;
}
public Course(int courseId, String courseName, String courseTime, String courseTeacher, int capacity) {
super();
this.courseId = courseId;
this.courseName = courseName;
this.courseTime = courseTime;
this.courseTeacher = courseTeacher;
this.capacity = capacity;
}
public Course(String courseName, String courseTime, String courseTeacher, int capacity) {
super();
this.courseName = courseName;
this.courseTime = courseTime;
this.courseTeacher = courseTeacher;
this.capacity = capacity;
}
public int getCourseId() {
return courseId;
}
public void setCourseId(int courseId) {
this.courseId = courseId;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String getCourseTime() {
return courseTime;
}
public void setCourseTime(String courseTime) {
this.courseTime = courseTime;
}
public String getCourseTeacher() {
return courseTeacher;
}
public void setCourseTeacher(String courseTeacher) {
this.courseTeacher = courseTeacher;
}
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public int getNumSelected() {
return numSelected;
}
public void setNumSelected(int numSelected) {
this.numSelected = numSelected;
}
}
package com.sjsq.model;
public class Selection {
int selectId;
int courseId = -1;
int Sno;
public Selection() {
super();
}
public Selection(int courseId, int sno) {
super();
this.courseId = courseId;
Sno = sno;
}
public int getSelectId() {
return selectId;
}
public void setSelectId(int selectId) {
this.selectId = selectId;
}
public int getCourseId() {
return courseId;
}
public void setCourseId(int courseId) {
this.courseId = courseId;
}
public int getSno() {
return Sno;
}
public void setSno(int sno) {
Sno = sno;
}
}
package com.sjsq.model;
public class Sinfo {
private int sno = -1;
private String sname;
private String ssex;
private String smajor;
private String stele;
public Sinfo() {
super();
}
public Sinfo(int sno) {
super();
this.sno = sno;
}
public Sinfo(int sno, String sname) {
super();
this.sno = sno;
this.sname = sname;
}
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getSsex() {
return ssex;
}
public void setSsex(String ssex) {
this.ssex = ssex;
}
public String getSmajor() {
return smajor;
}
public void setSmajor(String smajor) {
this.smajor = smajor;
}
public String getStele() {
return stele;
}
public void setStele(String stele) {
this.stele = stele;
}
}
package com.sjsq.model;
public class Student {
private int Sno = -1;
private String Spassword;
public Student() {
super();
}
public Student(int sno) {
super();
Sno = sno;
}
public Student(int sno, String spassword) {
super();
Sno = sno;
Spassword = spassword;
}
public int getSno() {
return Sno;
}
public void setSno(int sno) {
Sno = sno;
}
public String getSpassword() {
return Spassword;
}
public void setSpassword(String spassword) {
Spassword = spassword;
}
}
package com.sjsq.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DbUtil {
private String dbUrl = "jdbc:mysql://localhost:3306/courseselection_management_swing?serverTimezone=Asia/Shanghai";
private String dbUserName = "root";
private String dbPassword = "admin";
private String jdbcName = "com.mysql.cj.jdbc.Driver";
/** * 获取数据库连接 * * @return * @throws Exception */
public Connection getCon() throws Exception {
Class.forName(jdbcName);
Connection con = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
return con;
}
public void closeCon(Connection con) throws Exception {
if (con != null) {
con.close();
}
}
public static void main(String[] args) {
DbUtil dbUtil = new DbUtil();
try {
dbUtil.getCon();
System.out.println("数据库连接成功!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.sjsq.util;
public class StringUtil {
public static boolean isEmpty(String str) {
if ("".equals(str) || str == null) {
return true;
} else {
return false;
}
}
public static boolean isNotEmpty(String str) {
if (!"".equals(str) && str != null) {
return true;
} else {
return false;
}
}
}
package com.sjsq.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.sjsq.model.Admin;
import com.sjsq.model.Student;
public class LogOnDao {
/** * 登录验证 * * @param con * @param student * @return * @throws Exception */
public Student login(Connection con, Student student) throws Exception {
Student resultStu = null;
String sql = "select * from t_slogon where Sno=? and Spassword=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, student.getSno());
pstmt.setString(2, student.getSpassword());
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
resultStu = new Student();
resultStu.setSno(rs.getInt("Sno"));
resultStu.setSpassword(rs.getString("Spassword"));
}
return resultStu;
}
public Admin login(Connection con, Admin admin) throws Exception {
Admin resultAdmin = null;
String sql = "select * from t_adminlogon where adminId=? and password=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, admin.getAdminId());
pstmt.setString(2, admin.getPassword());
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
resultAdmin = new Admin();
resultAdmin.setAdminId(rs.getInt("adminId"));
resultAdmin.setPassword(rs.getString("password"));
}
return resultAdmin;
}
}
package com.sjsq.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.sjsq.model.Selection;
public class SelectionDao {
public int SelectionAdd(Connection con, Selection selection) throws Exception {
String sql = "insert into t_selection value(null,?,?)";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, selection.getCourseId());
pstmt.setInt(2, selection.getSno());
return pstmt.executeUpdate();
}
public int NumSelectedAdd(Connection con, int courseId) throws Exception {
String sql = "update t_course set numSelected=numSelected+1 where courseId=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, courseId);
return pstmt.executeUpdate();
}
public ResultSet SelectedList(Connection con, int sno) throws Exception {
String sql = "select * from t_selection s,t_course c where s.Sno=? and s.courseId=c.courseId ";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, sno);
return pstmt.executeQuery();
}
public int SelectionCancel(Connection con, Selection selection) throws Exception {
String sql = "delete from t_selection where courseId=? and Sno=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, selection.getCourseId());
pstmt.setInt(2, selection.getSno());
return pstmt.executeUpdate();
}
public int NumSelectedMinus(Connection con, int courseId) throws Exception {
String sql = "update t_course set numSelected=numSelected-1 where courseId=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, courseId);
return pstmt.executeUpdate();
}
}
package com.sjsq.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.sjsq.model.Sinfo;
import com.sjsq.model.Student;
import com.sjsq.util.StringUtil;
public class StudentDao {
public ResultSet StudentList(Connection con, Sinfo sinfo) throws SQLException {
StringBuffer sb = new StringBuffer("select * from t_sinfo ");
if (sinfo.getSno() != -1) {
sb.append(" and Sno=" + sinfo.getSno());
}
if (StringUtil.isNotEmpty(sinfo.getSname())) {
sb.append(" and Sname like '%" + sinfo.getSname() + "%'");
}
PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}
public ResultSet PasswordList(Connection con, Student student) throws SQLException {
StringBuffer sb = new StringBuffer("select * from t_slogon ");
if (student.getSno() != -1) {
sb.append("where Sno=" + student.getSno());
}
PreparedStatement pstmt = con.prepareStatement(sb.toString());
return pstmt.executeQuery();
}
public int PasswordModify(Connection con, Student student) throws Exception {
String sql = "update t_slogon set Spassword=? where Sno=? ";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, student.getSpassword());
pstmt.setInt(2, student.getSno());
return pstmt.executeUpdate();
}
}
package com.sjsq.view;
import java.awt.Font;
import java.sql.Connection;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.UIManager;
import com.sjsq.dao.LogOnDao;
import com.sjsq.model.Admin;
import com.sjsq.model.Student;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class LogOnFrm extends javax.swing.JFrame {
private ButtonGroup buttonGroup1;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JButton jb_logOn;
private JButton jb_reset;
private JRadioButton jrb_admin;
private JRadioButton jrb_student;
private JPasswordField passwordTxt;
private JFormattedTextField userNameTxt;
DbUtil dbUtil = new DbUtil();
LogOnDao logOnDao = new LogOnDao();
public static Student currentStudent;
public LogOnFrm() {
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
initComponents();
this.setLocationRelativeTo(null);
this.jrb_student.setSelected(true);
}
private void initComponents() {
buttonGroup1 = new ButtonGroup();
jLabel1 = new JLabel();
jLabel2 = new JLabel();
userNameTxt = new JFormattedTextField();
jLabel3 = new JLabel();
jrb_student = new JRadioButton();
jrb_admin = new JRadioButton();
jb_logOn = new JButton();
jb_reset = new JButton();
passwordTxt = new JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("用户登录页面");
setResizable(false);
jLabel1.setFont(new java.awt.Font("隶书", 1, 24));
jLabel1.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/sys.png")));
jLabel1.setText("学生选课系统");
jLabel2.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/userName.png")));
jLabel2.setText("账号");
jLabel3.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/password.png")));
jLabel3.setText("密码");
buttonGroup1.add(jrb_student);
jrb_student.setText("学生");
jrb_student.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/student.png")));
buttonGroup1.add(jrb_admin);
jrb_admin.setText("管理员");
jrb_admin.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/admin.png")));
jb_logOn.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/login.png")));
jb_logOn.setText("登录");
jb_logOn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_logOnActionPerformed(evt);
}
});
jb_reset.setIcon(new javax.swing.ImageIcon(LogOnFrm.class.getResource("/images/reset.png")));
jb_reset.setText("重置");
jb_reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_resetActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
.createSequentialGroup().addGap(106, 106, 106)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel1)
.addGroup(layout.createSequentialGroup().addGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup().addComponent(jLabel3).addGap(33, 33, 33))
.addGroup(layout.createSequentialGroup().addComponent(jLabel2).addGap(33, 33, 33)))
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(passwordTxt, 0, 0, Short.MAX_VALUE)
.addComponent(userNameTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 135,
Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup().addGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jb_logOn).addComponent(jrb_student))
.addGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29).addComponent(jb_reset))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jrb_admin,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)))))))
.addContainerGap(143, Short.MAX_VALUE)));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(77, Short.MAX_VALUE).addComponent(jLabel1).addGap(39, 39, 39)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2).addComponent(userNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3).addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jrb_student).addComponent(jrb_admin))
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jb_reset).addComponent(jb_logOn))
.addGap(58, 58, 58)));
pack();
}
private void jb_logOnActionPerformed(java.awt.event.ActionEvent evt) {
String userName = userNameTxt.getText();
String password = new String(passwordTxt.getPassword());
if (StringUtil.isEmpty(userName)) {
JOptionPane.showMessageDialog(this, "账号不能为空!");
return;
}
if (StringUtil.isEmpty(password)) {
JOptionPane.showMessageDialog(this, "密码不能为空!");
return;
}
Connection con = null;
if (this.jrb_student.isSelected()) {
Student student = new Student(Integer.parseInt(userName), password);
try {
con = dbUtil.getCon();
currentStudent = logOnDao.login(con, student);
if (currentStudent != null) {
this.dispose();
new MainFrm_student().setVisible(true);
} else {
JOptionPane.showMessageDialog(this, "用户名或密码错误!");
}
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "登录失败!");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (this.jrb_admin.isSelected()) {
Admin admin = new Admin(Integer.parseInt(userName), password);
try {
con = dbUtil.getCon();
Admin currentAdmin = logOnDao.login(con, admin);
if (currentAdmin != null) {
this.dispose();
new MainFrm_admin().setVisible(true);
} else {
JOptionPane.showMessageDialog(this, "用户名或密码错误!");
}
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "登录失败!");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
this.resetValue();
}
private void resetValue() {
this.userNameTxt.setText("");
this.passwordTxt.setText("");
this.jrb_student.setSelected(true);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LogOnFrm().setVisible(true);
}
});
}
}
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("");
}
}
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();
}
}
}
}
}
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();
}
}
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("");
}
}
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();
}
}
}
}
}
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();
}
}
}
}
}
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();
}
}
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);
}
}
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);
}
}
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实现网上商城系统
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存储信息
点击以下链接获取源码,数据库文件在sql文件下面。 Java+Swing+Mysql学生选课管理系统源码
如有侵权请联系我删除。
今日所行之事,是为明日大道所奠基,不慌张,缓缓来!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/183370.html原文链接:https://javaforall.cn