资源预览内容
第1页 / 共17页
第2页 / 共17页
第3页 / 共17页
第4页 / 共17页
第5页 / 共17页
第6页 / 共17页
第7页 / 共17页
第8页 / 共17页
第9页 / 共17页
第10页 / 共17页
亲,该文档总共17页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.border.*; import javax.swing.JOptionPane; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import java.sql.*;import java.awt.GridLayout;public class myStudent public myStudent() public static void main(String args) / TODO code application logic hereloginFrame lf=new loginFrame();lf.setVisible(true);lf.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0);); /主界面 class mainFrame extends JFrame implements ActionListener MenuBar myMenuBar=new MenuBar(); Menu myMenuFile,myMenuEdit,myMenuUser,myMenuAbout; MenuItem miNew,miOpen,miSave,miSaveAs,miExit; MenuItem miAdd,miEdit,miDel,miFind,miShow,miUser,miAbout;public JTable table = new JTable(); public DefaultTableModel mm ; public mainFrame()myMenuFile=new Menu(“文件“); miNew=new MenuItem(“新建“); miOpen=new MenuItem(“打开“); miSave=new MenuItem(“保存“); miExit=new MenuItem(“退出“); /miNew.enable(false); /miOpen.enable(false); /miSave.enable(false); /myMenuFile.add(miNew); /myMenuFile.add(miOpen); /myMenuFile.add(miSave); myMenuFile.add(miExit);myMenuEdit=new Menu(“数据编辑“); miFind=new MenuItem(“查找数据“); miAdd=new MenuItem(“添加数据“); miEdit=new MenuItem(“修改数据“); miDel=new MenuItem(“删除数据“); miShow=new MenuItem(“全部显示“); myMenuEdit.add(miFind); myMenuEdit.add(miAdd); myMenuEdit.add(miEdit); myMenuEdit.add(miDel); myMenuEdit.add(miShow);myMenuUser=new Menu(“用户“); miUser=new MenuItem(“编辑用户“); myMenuUser.add(miUser);myMenuAbout=new Menu(“我的作业“); miAbout=new MenuItem(“作业说明“); myMenuAbout.add(miAbout);myMenuBar.add(myMenuFile); myMenuBar.add(myMenuEdit); myMenuBar.add(myMenuUser); myMenuBar.add(myMenuAbout);String col = “学号“,“姓名“,“性别“,“民族“,“年龄“,“年级“,“班级“,“专业“;/创建属 性列名 mm= new DefaultTableModel(col,0); table.setModel(mm); JScrollPane tableScrollPane = new JScrollPane(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); public void freshTable(String sql) myConnection conn=new myConnection(); ResultSet rs; 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(Exception e) System.out.println(e.toString(); public void actionPerformed(ActionEvent e) /退出 if (e.getSource()=miExit) System.exit(0); /查找 else if(e.getSource()=miFind) findFrame ff=new findFrame(this); ff.setVisible(true); /添加 else if(e.getSource()=miAdd) addFrame af=new addFrame(this); af.setVisible(true); /修改 else if(e.getSource()=miEdit) if (table.getSelectedRow()=-1) JOptionPane.showMessageDialog(null, “请选择你要修改的内容“, “温馨提 示“, JOptionPane.INFORMATION_MESSAGE); else editFrame ef=new editFrame(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 学生信息表“); /删除 else if(e.getSource()=miDel) if (table.getSelectedRow()=-1) JOptionPane.showMessageDialog(null, “请选择你要删除的行“, “温馨提示“, JOptionPane.INFORMATION_MESSAGE);else String sql=“delete from 学生信息表 where 学号 = “+table.getValueAt(table.getSelectedRow(),0)+“; /JOptionPane.showMessageDialog(null, sql, “温馨提示“, JOptionPane.INFORMATION_MESSAGE);myConnection conn=new myConnection(); if (conn.executeSql(sql) JOptionPane.showMessageDialog(null, “成功删除“, “温馨提示“, JOptionPane.INFORMATION_MESSAGE); this.freshTable(“select * from 学生信息表“); else JOptionPane.showMessageDialog(null, “未知错误“, “删除失败“, JOptionPane.INFORMATION_MESSAGE); /显示 else if(e.getSource()=miShow) /JOptionPane.showMessageDialog(null, “未知错误“, “删除失败“, JOptionPane.INFORMATION_MESSAGE); this.freshTable(“select * from 学生信息表“); /用户管理 else if(e.getSource()=miUser) userFrame uf=new userFrame(); uf.setVisible(true); /关于 else if(e.getSource()=miAbout) aboutFrame af=new aboutFrame(); af.setVisible(true); class myConne
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号