您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 人事档案/员工关系 > JAVA学生信息管理系统源码
//AddStuInfo.javapackagecom.main;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjavax.swing.JButton;importjavax.swing.JComboBox;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;importjavax.swing.JOptionPane;importcom.bean.Student;importcom.dao.StudentDao;importcom.db.DB;importcom.main.DelteStudent.delAction;publicclassAddStuInfoextendsJFrame{StudentDaostudao=newStudentDao();DBdb=newDB();Connectionconn=db.getConnection();JTextFieldsnoText=null;JTextFieldsnameText=null;JComboBoxsexcom=null;JTextFieldageText=null;JComboBoxclasscom=null;JComboBoxdepartcom=null;publicvoidinit(){//窗体设计this.setLayout(null);this.setTitle(学生信息管理系统);this.setSize(500,400);JLabeltitle=newJLabel(学生信息维护模块---录入数据);title.setBounds(180,20,200,30);this.add(title);JLabelsnoLabel=newJLabel(学号);snoText=newJTextField();snoLabel.setBounds(20,60,40,25);snoText.setBounds(60,60,120,25);this.add(snoLabel);this.add(snoText);JLabelsnameLabel=newJLabel(姓名);snameText=newJTextField();snameLabel.setBounds(220,60,40,25);snameText.setBounds(260,60,120,25);this.add(snameLabel);this.add(snameText);JLabelsexlabel=newJLabel(性别);String[]sex={男,女};sexcom=newJComboBox(sex);sexlabel.setBounds(20,90,40,25);sexcom.setBounds(60,90,120,25);this.add(sexlabel);this.add(sexcom);JLabelageLabel=newJLabel(年龄);ageText=newJTextField();ageLabel.setBounds(220,90,40,25);ageText.setBounds(260,90,120,25);this.add(ageLabel);this.add(ageText);JLabelclasslabel=newJLabel(班级);String[]classes={信息081,信息082,物流081};classcom=newJComboBox(classes);classlabel.setBounds(20,120,40,25);classcom.setBounds(60,120,120,25);this.add(classlabel);this.add(classcom);JLabeldepartlabel=newJLabel(学院);String[]depart={造纸,理学院,机电学院};departcom=newJComboBox(depart);departlabel.setBounds(220,120,40,25);departcom.setBounds(260,120,120,25);this.add(departlabel);this.add(departcom);//录入数据JButtonaddbtn=newJButton(录入);addbtn.setBounds(150,180,60,30);addbtn.addActionListener(newaddAction());this.add(addbtn);//返回JButtonbackbtn=newJButton(返回);backbtn.setBounds(230,180,60,30);backbtn.addActionListener(newBackAction());this.add(backbtn);this.setLocationRelativeTo(null);//使窗体居中this.setResizable(false);//固定窗体大小this.setVisible(true);//设置窗体可见//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//窗体关闭时,程序结束}//获取文本框或选择框的值publicStudentgetStudent(){Studentstu=newStudent();Stringsno=snoText.getText();//获取输入的学号Stringsname=snameText.getText();//获取姓名Stringsex=(String)sexcom.getSelectedItem();//获取性别intage=Integer.parseInt(ageText.getText().trim());//获取年龄StringclassName=(String)classcom.getSelectedItem();//获取班级Stringdepart=(String)departcom.getSelectedItem();//获取学院//封装信息stu.setSno(sno);stu.setName(sname);stu.setSex(sex);stu.setAge(age);stu.setClassName(className);stu.setDepart(depart);returnstu;}publicstaticvoidmain(String[]args){AddStudentaddstu=newAddStudent();addstu.init();}//录入的监听器classaddActionimplementsActionListener{publicvoidactionPerformed(ActionEvente){Studentstu=getStudent();booleanb=studao.save(stu,conn);if(b){JOptionPane.showMessageDialog(null,数据录入成功!);}else{JOptionPane.showMessageDialog(null,学号已存在,数据录入失败!);}}}classBackActionimplementsActionListener{publicvoidactionPerformed(ActionEvente){MainFramem=newMainFrame();m.init();}}}//DelStuInfo.javapackagecom.main;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.SQLException;importjava.util.Vector;importjavax.swing.JButton;importjavax.swing.JComboBox;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importcom.bean.Student;importcom.dao.StudentDao;importcom.db.DB;importcom.main.AddStudent.BackAction;//删除学生信息publicclassDelStuInfoextendsJFrame{StudentDaostudao=newStudentDao();DBdb=newDB();Connectionconn=db.getConnection();JComboBoxsnocom=null;publicvoidinit(){//窗体设计this.setLayout(null);this.setTitle(学生信息管理系统);this.setSize(500,400);JLabeltitle=newJLabel(学生信息维护模块---删除数据);title.setBounds(180,20,200,30);this.add(title);//选择学号JLabelsnoLabel=newJLabel(请选择要删除学生信息的学号);snoLabel.setBounds(20,60,200,25);this.add(snoLabel);try{Vectorvec=studao.getSno();snocom=newJComboBox(vec);//将数据库里的学号信息装入下拉框中snocom.setBounds(30,90,150,25);}catch(SQLExceptione){e.printStackTrace();}this.add(snocom);//删除数据JButtondelbtn=newJButton(删除);delbtn.setBounds(100,180,60,30);delbtn.addActionListener(newdelAction());this.add(delbtn);//返回JButtonbackbtn=newJButton(返回);backbtn.setBounds(180,180,60,30);backbtn.addActionListener(newBackAction());this.add(backbtn);this.setLocationRelativeTo(null);//使窗体居中this.setResizable(false);//固定窗体大小this.setVisible(true);//设置窗体可见//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//窗体关闭时,程序结束}publicstaticvoidmain(String[]args){DelteStudentdelstu=newDelteStudent();delstu.init();}//删除的监听器classdelActionimplementsActionListener{publicvoidactionPerformed(ActionEvente){Stringdelsno=(String)snocom.getSelectedItem();booleanb=studao.delete(delsno,conn);if(b){JOptionPane.showMessageDialog(null,删除录入成功!);}else{JOptionPane.showMes
本文标题:JAVA学生信息管理系统源码
链接地址:https://www.777doc.com/doc-6271533 .html