基于java+mysql的swing+mysql学生管理系统java基础gui(java+gui)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于java+mysql的Swing+MySQL学生管理系统java基础gui(java+gui)
功能介绍:
学生信息管理,姓名,编号,性别,成绩,学号住址
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public String getCalssDesc() {
return calssDesc;
}
public void setCalssDesc(String calssDesc) {
this.calssDesc = calssDesc;
}
@Override
public String toString() {
return className;
}
}
package com.artisan.dao;
public class StudentManageInterFrm extends JInternalFrame {
private JTable studentTable;
private JTextField s_nameTxt;
private JTextField s_snTxt;
private JComboBox s_schoolClassJcb;
private JRadioButton manJrb ;
private JRadioButton femaleJrb ;
private JTextArea addressTxt;
private JComboBox schoolClassJcb ;
private DbUtil dbUtil=new DbUtil();
private SchoolClassDao schoolClassDao=new SchoolClassDao();
private StudentDao studentDao=new StudentDao();
private JTextField idTxt;
private JTextField nameTxt;
private final ButtonGroup buttonGroup = new ButtonGroup();
private JTextField deptTxt;
private JTextField snTxt;
/**
* Create the frame.
*/
public StudentManageInterFrm() {
setClosable(true);
if(StringUtil.isEmpty(price)){
JOptionPane.showMessageDialog(null, "学生学院不能为空!");
return;
}
String sex="";
if(manJrb.isSelected()){
sex="男";
}else if(femaleJrb.isSelected()){
sex="女";
}
SchoolClass bookType=(SchoolClass) schoolClassJcb.getSelectedItem();
int bookTypeId=bookType.getId();
Student book=new Student(bookName,author, sex, price , bookTypeId, bookDesc);
Connection con=null;
try{
con=dbUtil.getCon();
int addNum=studentDao.add(con, book);
if(addNum==1){
JOptionPane.showMessageDialog(null, "学生添加成功!");
resetValue();
}else{
JOptionPane.showMessageDialog(null, "学生添加失败!");
}
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, "学生添加失败!");
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 重置表单
*/
private void resetValue(){
this.studentTxt.setText("");
this.snTxt.setText("");
/**
* 重置表单
*/
private void resetValue(){
this.classNameTxt.setText("");
this.classDescTxt.setText("");
}
}
package com.artisan.view;
public class MainFrm extends JFrame {
private JPanel contentPane;
private JDesktopPane table =null;
/**
* Create the frame.
*/
public MainFrm() {
setTitle("学生信息管理系统主界面");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
.addGap(30)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(label_4)
.addComponent(addressTxt, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(button)
.addComponent(button_1))
.addGap(42))
// .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
// .addComponent(label)
// .addComponent(gradeTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
// .addComponent(label_1)
// .addComponent(snTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
);
getContentPane().setLayout(groupLayout);
// 设置文本域边框
addressTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false));
fillBookType();
}
/**
* 重置事件处理
* @param e
*/
private void resetValueActionPerformed(ActionEvent e) {
this.resetValue();
}
/**
* 学生添加事件处理
* @param e
*/
private void bookAddActionPerformed(ActionEvent evt) {
String bookName=this.studentTxt.getText();
String author=this.snTxt.getText();
String price=this.deptTxt.getText();
String bookDesc=this.addressTxt.getText();
if(StringUtil.isEmpty(bookName)){
JOptionPane.showMessageDialog(null, "学生姓名不能为空!");
}
public static void main(String[] args) {
DbUtil dbUtil = new DbUtil();
try {
dbUtil.getCon();
System.out.println("数据库连接成功!");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("数据库连接失败");
}
}
}
package com.artisan.view;
public class ArtisanInterFrm extends JInternalFrame {
/**
* Create the frame.
*/
public ArtisanInterFrm() {
//getContentPane().setBackground(Color.RED);
setIconifiable(true);
setClosable(true);
setTitle("关于系统");
setBounds(100, 100, 450, 300);
JLabel lblNewLabel = new JLabel("");
lblNewLabel.setIcon(new ImageIcon(ArtisanInterFrm.class.getResource("/images/artisan.png")));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
}catch(Exception e){
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
package com.artisan.view;
public class SchoolClassManageInterFrm extends JInternalFrame {
private JTable schoolClassTable;
private JTextArea classDescTxt ;
/**
* 更新班级
* @param con
* @param schoolClass
* @return
* @throws Exception
*/
public int update(Connection con,SchoolClass schoolClass)throws Exception{
String sql="update t_school_class set className=?,classDesc=? where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, schoolClass.getClassName());
pstmt.setString(2, schoolClass.getCalssDesc());
pstmt.setInt(3, schoolClass.getId());
return pstmt.executeUpdate();
}
}
package com.artisan.model;
/**
* 学生实体
*
*/
public class Student {
private int id; // 编号
private String name; // 姓名
private String sn; // 学号
private String sex; // 性别
private String dept; // 成绩
private Integer classId; // 班级Id
private String className; // 班级名称
private String address; // 家庭住址
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(String name, String sn, String sex, String dept, Integer calssId, String address) {
super();
this.name = name;
this.sn = sn;
this.sex = sex;
this.dept = dept;
this.classId = calssId;
this.address = address;
}
private Integer classId; // 班级Id
private String className; // 班级名称
private String address; // 家庭住址
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(String name, String sn, String sex, String dept, Integer calssId, String address) {
super();
this.name = name;
this.sn = sn;
this.sex = sex;
this.dept = dept;
this.classId = calssId;
this.address = address;
}
public Student(int id, String name, String sn, String sex, String dept, Integer calssId, String address) {
super();
this.id = id;
this.name = name;
this.sn = sn;
this.sex = sex;
this.dept = dept;
this.classId = calssId;
this.address = address;
}
public Student(String name, String sn, Integer calssId) {
super();
this.name = name;
this.sn = sn;
this.classId = calssId;
}
public int getId() {
return id;
idTxt = new JTextField();
idTxt.setEditable(false);
idTxt.setColumns(10);
JLabel lblNewLabel_1 = new JLabel("学生姓名");
nameTxt = new JTextField();
nameTxt.setColumns(10);
JLabel label_3 = new JLabel("学生性别");
manJrb = new JRadioButton("\u7537");
buttonGroup.add(manJrb);
manJrb.setSelected(true);
femaleJrb = new JRadioButton("\u5973");
buttonGroup.add(femaleJrb);
JLabel label_4 = new JLabel("成绩分数");
deptTxt = new JTextField();
deptTxt.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("学生学号");
snTxt = new JTextField();
snTxt.setColumns(10);
JLabel label_5 = new JLabel("所属班级");
schoolClassJcb = new JComboBox();
JLabel label_6 = new JLabel("家庭住址");
addressTxt = new JTextArea();
JButton button_1 = new JButton("\u4FEE\u6539");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
studentUpdateActionPerformed(evt);
}
});
button_1.setIcon(new ImageIcon(StudentManageInterFrm.class.getResource("/images/modify.png")));
JButton button_2 = new JButton("\u5220\u9664");
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
studentDeleteActionPerformed(evt);
}
public Student(String name, String sn, Integer calssId) {
super();
this.name = name;
this.sn = sn;
this.classId = calssId;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getSex() {
return sex;
}
this.fillTable(schoolClass);
}
/**
* 初始化表格
* @param schoolClass
*/
private void fillTable(SchoolClass schoolClass){
DefaultTableModel dtm=(DefaultTableModel) schoolClassTable.getModel();
dtm.setRowCount(0); // 设置成0行
Connection con=null;
try{
con=dbUtil.getCon();
ResultSet rs=schoolClassDao.list(con, schoolClass);
while(rs.next()){
Vector v=new Vector();
v.add(rs.getString("id"));
v.add(rs.getString("className"));
v.add(rs.getString("classDesc"));
dtm.addRow(v);
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 重置表单
*/
private void resetValue(){
this.idTxt.setText("");
this.classNameTxt.setText("");
this.classDescTxt.setText("");
}
}
package com.artisan.view;
}
package com.artisan.model;
/**
* 学生实体
*
*/
public class Student {
private int id; // 编号
private String name; // 姓名
private String sn; // 学号
private String sex; // 性别
private String dept; // 成绩
private Integer classId; // 班级Id
private String className; // 班级名称
private String address; // 家庭住址
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(String name, String sn, String sex, String dept, Integer calssId, String address) {
super();
this.name = name;
this.sn = sn;
this.sex = sex;
this.dept = dept;
this.classId = calssId;
this.address = address;
}
this.fillBookType("search");
this.fillBookType("modify");
this.fillTable(new Student());
}
/**
* 学生信息删除事件处理
* @param evt
*/
private void studentDeleteActionPerformed(ActionEvent evt) {
String id=idTxt.getText();
if(StringUtil.isEmpty(id)){
JOptionPane.showMessageDialog(null, "请选择要删除的记录");
return;
}
int n=JOptionPane.showConfirmDialog(null, "确定要删除该记录吗?");
if(n==0){
Connection con=null;
try{
con=dbUtil.getCon();
int deleteNum=studentDao.delete(con, id);
if(deleteNum==1){
JOptionPane.showMessageDialog(null, "删除成功");
this.resetValue();
this.fillTable(new Student());
}else{
JOptionPane.showMessageDialog(null, "删除失败");
}
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, "删除失败");
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
con=dbUtil.getCon();
int modifyNum=schoolClassDao.update(con, bookType);
if(modifyNum==1){
JOptionPane.showMessageDialog(null, "修改成功");
this.resetValue();
this.fillTable(new SchoolClass());
}else{
JOptionPane.showMessageDialog(null, "修改失败");
}
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, "修改失败");
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 表格行点击事件处理
* @param e
*/
private void schoolClassTableMousePressed(MouseEvent evt) {
int row=schoolClassTable.getSelectedRow();
idTxt.setText((String)schoolClassTable.getValueAt(row, 0));
classNameTxt.setText((String)schoolClassTable.getValueAt(row, 1));
classDescTxt.setText((String)schoolClassTable.getValueAt(row, 2));
}
/**
* 班级信息搜索事件处理
* @param evt
*/
private void schoolClassSearchActionPerformed(ActionEvent evt) {
String s_className=this.s_classNameTxt.getText();
SchoolClass schoolClass=new SchoolClass();
schoolClass.setClassName(s_className);
.addGap(111)
.addComponent(lblNewLabel))
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(101)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_1)
.addComponent(lblNewLabel_2)
.addComponent(btnNewButton))
.addGap(32)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(btnNewButton_1)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(passwordTxt)
.addComponent(userNameTxt, GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)))))
.addContainerGap(111, Short.MAX_VALUE))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(30)
.addComponent(lblNewLabel)
.addGap(26)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblNewLabel_1)
.addGap(29)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2)
.addComponent(passwordTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(36)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(btnNewButton)
.addComponent(btnNewButton_1))
.addContainerGap(60, Short.MAX_VALUE))
);
contentPane.setLayout(gl_contentPane);
// 设置JFrame居中显示
this.setLocationRelativeTo(null);
}
/**
* 登录事件处理
* @param e
*/
private void loginActionPerformed(ActionEvent evt) {
String userName=this.userNameTxt.getText();
String password=new String(this.passwordTxt.getPassword());
if(StringUtil.isEmpty(userName)){
JOptionPane.showMessageDialog(null, "用户名不能为空!");
return;
}
* @throws Exception
*/
public ResultSet list(Connection con,Student student)throws Exception{
StringBuffer sb=new StringBuffer("select * from t_student b,t_school_class bt where b.classId=bt.id");
if(StringUtil.isNotEmpty(student.getName())){
sb.append(" and b.name like '%"+student.getName()+"%'");
}
if(StringUtil.isNotEmpty(student.getSn())){
sb.append(" and b.sn like '%"+student.getSn()+"%'");
}
if(student.getClassId()!=null && student.getClassId()!=-1){
sb.append(" and b.classId="+student.getClassId());
}
PreparedStatement pstmt=con.prepareStatement(sb.toString());
return pstmt.executeQuery();
}
/**
* 学生信息删除
* @param con
* @param id
* @return
* @throws Exception
*/
public int delete(Connection con,String id)throws Exception{
String sql="delete from t_student where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, id);
return pstmt.executeUpdate();
}
/**
* 学生信息修改
* @param con
* @param student
* @return
* @throws Exception
*/
public int update(Connection con,Student student)throws Exception{
String sql="update t_student set name=?,sn=?,sex=?,dept=?,address=?,classId=? where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, student.getName());
pstmt.setString(2, student.getSn());
pstmt.setString(3, student.getSex());
pstmt.setString(4, student.getDept());
pstmt.setString(5, student.getAddress());
pstmt.setInt(6, student.getClassId());
pstmt.setInt(7, student.getId());
return pstmt.executeUpdate();
}
/**
* 指定班级下是否存在学生
int deleteNum=schoolClassDao.delete(con, id);
if(deleteNum==1){
JOptionPane.showMessageDialog(null, "删除成功");
this.resetValue();
this.fillTable(new SchoolClass());
}else{
JOptionPane.showMessageDialog(null, "删除失败");
}
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, "删除失败");
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/**
* 班级信息修改事件处理
* @param evt
*/
private void schoolClassUpdateActionEvent(ActionEvent evt) {
String id=idTxt.getText();
String className=classNameTxt.getText();
String classDesc=classDescTxt.getText();
if(StringUtil.isEmpty(id)){
JOptionPane.showMessageDialog(null, "请选择要修改的记录");
return;
}
if(StringUtil.isEmpty(className)){
JOptionPane.showMessageDialog(null, "班级信息名称不能为空");
return;
}
SchoolClass bookType=new SchoolClass(Integer.parseInt(id),className,classDesc);
Connection con=null;
try{
con=dbUtil.getCon();
int modifyNum=schoolClassDao.update(con, bookType);
if(modifyNum==1){
JButton btnNewButton_1 = new JButton("重置");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
resetValueActionPerformed(e);
}
});
btnNewButton_1.setIcon(new ImageIcon(SchoolClassAddInterFrm.class.getResource("/images/reset.png")));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(86)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(classNameTxt, GroupLayout.PREFERRED_SIZE, 185, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_1)
.addComponent(btnNewButton))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(btnNewButton_1)
.addComponent(classDescTxt))))
.addContainerGap(69, GroupLayout.PREFERRED_SIZE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(56)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel)
.addComponent(classNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(29)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_1)
.addComponent(classDescTxt, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(btnNewButton)
.addComponent(btnNewButton_1))
.addGap(28))
);
getContentPane().setLayout(groupLayout);
setResizable(false);
setTitle("学生信息管理系统");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 343);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JLabel lblNewLabel = new JLabel("学生信息管理系统");
lblNewLabel.setFont(new Font("宋体", Font.BOLD, 23));
lblNewLabel.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/logo.png")));
JLabel lblNewLabel_1 = new JLabel("用户名:");
lblNewLabel_1.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/userName.png")));
JLabel lblNewLabel_2 = new JLabel("密 码:");
lblNewLabel_2.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/password.png")));
userNameTxt = new JTextField();
userNameTxt.setColumns(10);
passwordTxt = new JPasswordField();
JButton btnNewButton = new JButton("登录");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loginActionPerformed(e);
}
});
btnNewButton.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/login.png")));
JButton btnNewButton_1 = new JButton("重置");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
resetValueActionPerformed(e);
}
});
btnNewButton_1.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/reset.png")));
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(111)
.addComponent(lblNewLabel))
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(101)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_1)
this.fillTable(book);
}
/**
* 初始化下拉框
* @param type 下拉框类型
*/
private void fillBookType(String type){
Connection con=null;
SchoolClass schoolClass=null;
try{
con=dbUtil.getCon();
ResultSet rs=schoolClassDao.list(con, new SchoolClass());
if("search".equals(type)){
schoolClass=new SchoolClass();
schoolClass.setClassName("请选择...");
schoolClass.setId(-1);
this.s_schoolClassJcb.addItem(schoolClass);
}
while(rs.next()){
schoolClass=new SchoolClass();
schoolClass.setClassName(rs.getString("className"));
schoolClass.setId(rs.getInt("id"));
if("search".equals(type)){
this.s_schoolClassJcb.addItem(schoolClass);
}else if("modify".equals(type)){
this.schoolClassJcb.addItem(schoolClass);
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 初始化表格数据
* @param book
*/
private void fillTable(Student book){
DefaultTableModel dtm=(DefaultTableModel) studentTable.getModel();
dtm.setRowCount(0); // 设置成0行
Connection con=null;
try{
con=dbUtil.getCon();
ResultSet rs=studentDao.list(con, book);
while(rs.next()){
Vector v=new Vector();
}
User user=new User(userName,password);
Connection con=null;
try {
con=dbUtil.getCon();
User currentUser=userDao.login(con, user);
if(currentUser!=null){
dispose();
new MainFrm().setVisible(true);
}else{
JOptionPane.showMessageDialog(null, "用户名或者密码错误!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 重置事件处理
* @param e
*/
private void resetValueActionPerformed(ActionEvent evt) {
this.userNameTxt.setText("");
this.passwordTxt.setText("");
}
}
package com.artisan.view;
private void resetValueActionPerformed(ActionEvent e) {
this.resetValue();
}
/**
* 学生添加事件处理
* @param e
*/
private void bookAddActionPerformed(ActionEvent evt) {
String bookName=this.studentTxt.getText();
String author=this.snTxt.getText();
String price=this.deptTxt.getText();
String bookDesc=this.addressTxt.getText();
if(StringUtil.isEmpty(bookName)){
JOptionPane.showMessageDialog(null, "学生姓名不能为空!");
return;
}
if(StringUtil.isEmpty(author)){
JOptionPane.showMessageDialog(null, "学生学号不能为空!");
return;
}
if(StringUtil.isEmpty(price)){
JOptionPane.showMessageDialog(null, "学生学院不能为空!");
return;
}
String sex="";
if(manJrb.isSelected()){
sex="男";
}else if(femaleJrb.isSelected()){
sex="女";
}
SchoolClass bookType=(SchoolClass) schoolClassJcb.getSelectedItem();
int bookTypeId=bookType.getId();
Student book=new Student(bookName,author, sex, price , bookTypeId, bookDesc);
public class SchoolClassManageInterFrm extends JInternalFrame {
private JTable schoolClassTable;
private JTextArea classDescTxt ;
private DbUtil dbUtil=new DbUtil();
private SchoolClassDao schoolClassDao=new SchoolClassDao();
private StudentDao studentDao=new StudentDao();
private JTextField s_classNameTxt;
private JTextField idTxt;
private JTextField classNameTxt;
/**
* Create the frame.
*/
public SchoolClassManageInterFrm() {
setClosable(true);
setIconifiable(true);
setTitle("班级信息管理界面");
setBounds(100, 100, 507, 481);
JScrollPane scrollPane = new JScrollPane();
JLabel label = new JLabel("班级信息名称");
s_classNameTxt = new JTextField();
s_classNameTxt.setColumns(10);
buttonGroup.add(manJrb);
manJrb.setSelected(true);
femaleJrb = new JRadioButton("女");
buttonGroup.add(femaleJrb);
JLabel label_3 = new JLabel("成绩分数");
deptTxt = new JTextField();
deptTxt.setColumns(10);
JLabel label_4 = new JLabel("家庭住址");
addressTxt = new JTextArea();
JLabel label_5 = new JLabel("所在班级");
schoolClassJcb = new JComboBox();
gradeTxt = new JTextField();
gradeTxt.setColumns(10);
JButton button = new JButton("添加");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
bookAddActionPerformed(e);
}
});
button.setIcon(new ImageIcon(StudentAddInterFrm.class.getResource("/images/add.png")));
JButton button_1 = new JButton("重置");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
resetValueActionPerformed(e);
}
});
button_1.setIcon(new ImageIcon(StudentAddInterFrm.class.getResource("/images/reset.png")));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(42)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
s_snTxt = new JTextField();
s_snTxt.setColumns(10);
JLabel label_2 = new JLabel("所属班级");
s_schoolClassJcb = new JComboBox();
JButton button = new JButton("\u67E5\u8BE2");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
bookSearchActionPerformed(e);
}
});
button.setIcon(new ImageIcon(StudentManageInterFrm.class.getResource("/images/search.png")));
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addGap(19)
.addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(s_nameTxt, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(label_1)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(s_snTxt, GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(label_2)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(s_schoolClassJcb, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(button)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(label)
.addComponent(s_nameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label_1)
.addComponent(s_snTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label_2)
.addComponent(s_schoolClassJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(button))
.addGap(16))
);
panel.setLayout(gl_panel);