您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > 64用java编教务系统的源码
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjavax.swing.border.*;importjavax.swing.JOptionPane;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.table.DefaultTableModel;importjavax.swing.table.TableColumn;importjava.sql.*;importjava.awt.GridLayout;publicclassmyStudent{publicmyStudent(){}publicstaticvoidmain(String[]args){//TODOcodeapplicationlogichereloginFramelf=newloginFrame();lf.setVisible(true);lf.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});}}//主界面classmainFrameextendsJFrameimplementsActionListener{MenuBarmyMenuBar=newMenuBar();MenumyMenuFile,myMenuEdit,myMenuUser,myMenuAbout;MenuItemmiNew,miOpen,miSave,miSaveAs,miExit;MenuItemmiAdd,miEdit,miDel,miFind,miShow,miUser,miAbout;publicJTabletable=newJTable();publicDefaultTableModelmm;publicmainFrame(){myMenuFile=newMenu(文件);miNew=newMenuItem(新建);miOpen=newMenuItem(打开);miSave=newMenuItem(保存);miExit=newMenuItem(退出);//miNew.enable(false);//miOpen.enable(false);//miSave.enable(false);//myMenuFile.add(miNew);//myMenuFile.add(miOpen);//myMenuFile.add(miSave);myMenuFile.add(miExit);myMenuEdit=newMenu(数据编辑);miFind=newMenuItem(查找数据);miAdd=newMenuItem(添加数据);miEdit=newMenuItem(修改数据);miDel=newMenuItem(删除数据);miShow=newMenuItem(全部显示);myMenuEdit.add(miFind);myMenuEdit.add(miAdd);myMenuEdit.add(miEdit);myMenuEdit.add(miDel);myMenuEdit.add(miShow);myMenuUser=newMenu(用户);miUser=newMenuItem(编辑用户);myMenuUser.add(miUser);myMenuAbout=newMenu(我的作业);miAbout=newMenuItem(作业说明);myMenuAbout.add(miAbout);myMenuBar.add(myMenuFile);myMenuBar.add(myMenuEdit);myMenuBar.add(myMenuUser);myMenuBar.add(myMenuAbout);String[]col={学号,姓名,性别,民族,年龄,年级,班级,专业};//创建属性列名mm=newDefaultTableModel(col,0);table.setModel(mm);JScrollPanetableScrollPane=newJScrollPane(table);this.setMenuBar(myMenuBar);this.add(tableScrollPane);miExit.addActionListener(this);miFind.addActionListener(this);miAdd.addActionListener(this);miEdit.addActionListener(this);miDel.addActionListener(this);miShow.addActionListener(this);miUser.addActionListener(this);miAbout.addActionListener(this);}publicvoidfreshTable(Stringsql){myConnectionconn=newmyConnection();ResultSetrs;rs=conn.getResult(sql);if(rs!=null){try{mm.setRowCount(0);table.setModel(mm);while(rs.next()){String学号=rs.getString(学号);String姓名=rs.getString(姓名);String性别=rs.getString(性别);String民族=rs.getString(民族);String年龄=rs.getString(年龄);String年级=rs.getString(年级);String班级=rs.getString(班级);String专业=rs.getString(专业);String[]cloumns={学号,姓名,性别,民族,年龄,年级,班级,专业};mm.addRow(cloumns);}//table.clearSelection();table.setModel(mm);}catch(Exceptione){System.out.println(e.toString());}}}publicvoidactionPerformed(ActionEvente){//退出if(e.getSource()==miExit){System.exit(0);//查找}elseif(e.getSource()==miFind){findFrameff=newfindFrame(this);ff.setVisible(true);//添加}elseif(e.getSource()==miAdd){addFrameaf=newaddFrame(this);af.setVisible(true);//修改}elseif(e.getSource()==miEdit){if(table.getSelectedRow()==-1){JOptionPane.showMessageDialog(null,请选择你要修改的内容,温馨提示,JOptionPane.INFORMATION_MESSAGE);}else{editFrameef=neweditFrame(this);ef.学号.setText((String)table.getValueAt(table.getSelectedRow(),0));ef.姓名.setText((String)table.getValueAt(table.getSelectedRow(),1));ef.性别.setText((String)table.getValueAt(table.getSelectedRow(),2));ef.民族.setText((String)table.getValueAt(table.getSelectedRow(),3));ef.年龄.setText((String)table.getValueAt(table.getSelectedRow(),4));ef.年级.setText((String)table.getValueAt(table.getSelectedRow(),5));ef.班级.setText((String)table.getValueAt(table.getSelectedRow(),6));ef.专业.setText((String)table.getValueAt(table.getSelectedRow(),7));ef.setVisible(true);this.freshTable(select*from学生信息表);}//删除}elseif(e.getSource()==miDel){if(table.getSelectedRow()==-1){JOptionPane.showMessageDialog(null,请选择你要删除的行,温馨提示,JOptionPane.INFORMATION_MESSAGE);}else{Stringsql=deletefrom学生信息表where学号='+table.getValueAt(table.getSelectedRow(),0)+';//JOptionPane.showMessageDialog(null,sql,温馨提示,JOptionPane.INFORMATION_MESSAGE);myConnectionconn=newmyConnection();if(conn.executeSql(sql)){JOptionPane.showMessageDialog(null,成功删除,温馨提示,JOptionPane.INFORMATION_MESSAGE);this.freshTable(select*from学生信息表);}else{JOptionPane.showMessageDialog(null,未知错误,删除失败,JOptionPane.INFORMATION_MESSAGE);}}//显示}elseif(e.getSource()==miShow){//JOptionPane.showMessageDialog(null,未知错误,删除失败,JOptionPane.INFORMATION_MESSAGE);this.freshTable(select*from学生信息表);//用户管理}elseif(e.getSource()==miUser){userFrameuf=newuserFrame();uf.setVisible(true);//关于}elseif(e.getSource()==miAbout){aboutFrameaf=newaboutFrame();af.setVisible(true);}}}classmyConnection{ResultSetre;Stringstrurl=jdbc:odbc:driver={MicrosoftAccessDriver(*.mdb)};DBQ=学生管理数据库.mdb;publicmyConnection(){}publicResultSetgetResult(Stringsql){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectionconn=DriverManager.getConnection(strurl);Statementstmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);ResultSetre=stmt.executeQuery(sql);returnre;}catch(Exceptione){System.out.println(getResult--
本文标题:64用java编教务系统的源码
链接地址:https://www.777doc.com/doc-4580020 .html