您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > JAVA学生管理系统完美简单版
importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjava.util.*;importjavax.swing.*;importjavax.swing.border.*;importjavax.swing.JDialog;importjavax.swing.JFrame;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.util.Vector;importjavax.swing.table.*;publicclassXsglxtextendsJFrameimplementsActionListener{JFrameframe;JPanelmb1,mb2,mb3,mb4,mb5;JLabelbq1,bq2,bq4,bq5,bq6;JTextFieldwbk1;JButtonan1,an2,an3,an4,an5;JTablebg1;JScrollPanegd1;Xsxxxsxx2;JTextFieldwby;JPasswordFieldmima;publicstaticvoidmain(String[]args)throwsException{Xsglxtxs=newXsglxt();}publicXsglxt(){ImageIconicon=newImageIcon(C:/Users/Administrator/Desktop/A.jpg);frame=newJFrame(学生管理系统登入);an5=newJButton(登入);an5.setActionCommand(dengru);an5.setBackground(Color.GREEN);an5.addActionListener(this);mb3=newJPanel();mb4=newJPanel();mb5=newJPanel();bq2=newJLabel(欢迎来到福建工程学院国脉信息学院的学生管理系统);bq2.setFont(newFont(黑体,Font.TYPE1_FONT,20));Borderb=BorderFactory.createLineBorder(Color.red);Bordera=BorderFactory.createTitledBorder(b);mb3.setBorder(a);bq2.setVerticalAlignment(JLabel.NORTH);mb3.add(bq2);mb3.setBackground(Color.GREEN);bq4=newJLabel(管理者);bq5=newJLabel(密码);bq6=newJLabel(icon);wby=newJTextField(20);mima=newJPasswordField(20);Borderc=BorderFactory.createTitledBorder(b);mb4.setBorder(c);mb4.setLayout(newFlowLayout(FlowLayout.CENTER));mb4.add(bq6);mb4.add(bq4);mb4.add(wby);mb4.add(bq5);mb4.add(mima);mb4.add(an5);mb4.setBackground(Color.blue);frame.getContentPane().add(mb3,BorderLayout.NORTH);frame.getContentPane().add(mb4,BorderLayout.CENTER);frame.getContentPane().add(mb5,BorderLayout.SOUTH);mb1=newJPanel();bq1=newJLabel(请输入姓名);wbk1=newJTextField(10);an1=newJButton(查询);an1.addActionListener(this);an1.setActionCommand(chaxun);an1.setBackground(Color.red);mb1.add(bq1);mb1.add(wbk1);mb1.add(an1);mb1.setBackground(Color.green);mb2=newJPanel();an2=newJButton(添加);an2.addActionListener(this);an2.setActionCommand(tianjia);an3=newJButton(修改);an2.setBackground(Color.red);an3.addActionListener(this);an3.setActionCommand(xiugai);an3.setBackground(Color.red);an4=newJButton(删除);an4.addActionListener(this);an4.setActionCommand(shanchu);an4.setBackground(Color.red);mb2.add(an2);mb2.add(an3);mb2.add(an4);mb2.setBackground(Color.blue);xsxx2=newXsxx();bg1=newJTable(xsxx2);gd1=newJScrollPane(bg1);frame.setSize(900,225);frame.setLocation(201,181);frame.setResizable(false);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);this.add(gd1);this.add(mb1,North);this.add(mb2,South);this.setTitle(学生管理系统);this.setSize(700,300);this.setLocation(201,181);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(false);}publicvoidactionPerformed(ActionEvente){char[]pw=mima.getPassword();Stringpasssword=newString(pw);if(e.getActionCommand().equals(dengru)){if(wby.getText().equals()&&passsword.equals())JOptionPane.showMessageDialog(frame,您没有输入用户名和密码,请输入,error,JOptionPane.ERROR_MESSAGE);elseif(wby.getText().equals(山川)&&passsword.equals(1314520)){this.setVisible(true);frame.setVisible(false);}elseJOptionPane.showMessageDialog(frame,输入错误,请重新输入,error,JOptionPane.ERROR_MESSAGE);}elseif(e.getActionCommand().equals(chaxun)){Stringxingming=this.wbk1.getText().trim();if(xingming.equals()){xsxx2=newXsxx();bg1.setModel(xsxx2);}else{Stringsql=select*fromxueshengwhere姓名='+xingming+';xsxx2=newXsxx(sql);bg1.setModel(xsxx2);}}elseif(e.getActionCommand().equals(tianjia)){Tianjiatj=newTianjia(this,添加学生信息,true);xsxx2=newXsxx();bg1.setModel(xsxx2);}elseif(e.getActionCommand().equals(xiugai)){intii=this.bg1.getSelectedRow();if(ii==-1){JOptionPane.showMessageDialog(this,请选中要修改的行);return;}newXiugai(this,修改学生信息,true,xsxx2,ii);xsxx2=newXsxx();bg1.setModel(xsxx2);}elseif(e.getActionCommand().equals(shanchu)){intii=this.bg1.getSelectedRow();if(ii==-1){JOptionPane.showMessageDialog(this,请选中要删除的行);return;}Stringst=(String)xsxx2.getValueAt(ii,0);PreparedStatementps=null;Connectionct=null;ResultSetrs=null;Statementsm=null;try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);ct=DriverManager.getConnection(jdbc:odbc:sqlserver,sa,ydyd4488321);ps=ct.prepareStatement(deletefromxueshengwhere学号=?);ps.setString(1,st);ps.executeUpdate();}catch(Exceptione2){}finally{try{if(rs!=null){rs.close();}if(ps!=null){ps.close();}if(ct!=null){ct.close();}}catch(Exceptione3){}}xsxx2=newXsxx();bg1.setModel(xsxx2);}}}classXsxxextendsAbstractTableModel{Vectorziduan,jilu;PreparedStatementps=null;Connectionct=null;ResultSetrs=null;publicintgetRowCount(){returnthis.jilu.size();}publicintgetColumnCount(){returnthis.ziduan.size();}publicObjectgetValueAt(inthang,intlie){return((Vector)this.jilu.get(hang)).get(lie);}publicXsxx(){this.sqlyj(select*fromxuesheng);}publicXsxx(Stringss){this.sqlyj(ss);}publicStringgetColumnName(inte){return(String)this.ziduan.get(e);}publicvoidsqlyj(Stringsql){ziduan=newVector();ziduan.add(学号);ziduan.add(姓名);ziduan.add(性别);ziduan.add(年龄);ziduan.add(籍贯);ziduan.add(所在院系);ziduan.add(担任职务);zi
本文标题:JAVA学生管理系统完美简单版
链接地址:https://www.777doc.com/doc-4326531 .html