java项目学生成绩管理系统_第1页
java项目学生成绩管理系统_第2页
java项目学生成绩管理系统_第3页
java项目学生成绩管理系统_第4页
java项目学生成绩管理系统_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

-.z.《Java程序设计实训》学生成绩管理系统设计数据库:CREATEDATABASE学生成绩管理系统(1)教师信息表创建:createtable教师信息表(教师IDvarchar(8)primarykey,教师varchar(8)notnullunique,登录密码varchar(8)notnull,)(2)学籍信息表创建:createtable学籍信息表(**varchar(15)primarykey,varchar(8)notnull,年龄varchar(10),出生日期varchar(10),性别varchar(4),班级varchar(8)notnull,专业varchar(5),民族varchar(10),登录密码varchar(6)notnull)(3)成绩信息表创建:createtable成绩信息表(**varchar(15),计算机网络varchar(8),计算机专业英语smallint,计算机信息技术基础smallint,Java程序设计smallint,数据库应用实训教程smallint,高等数学smallint,*mlsmallint,)概要结构分析:学生成绩管理系统登录界面学生成绩管理系统登录界面添加学生信息查看学生成绩查看学生信息查看学生成绩查看学生信息删除学生信息修改学生信息添加学生成绩添加学生信息学生登录教师登录添加学生信息查看学生成绩查看学生信息查看学生成绩查看学生信息删除学生信息修改学生信息添加学生成绩添加学生信息学生登录教师登录1.登录界面和主界面importjava*.swing.*;import;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;classmyConnection{ResultSetre;publicmyConnection(){}publicResultSetgetResult(Stringsql){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connectionconn=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123"); Statementstmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSetre=stmt.e*ecuteQuery(sql);returnre;}catch(E*ceptione){ System.out.println("getResult------"+e.toString());returnnull;}}publicbooleane*ecuteSql(Stringsql){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connectionconn=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123"); Statementstmt=conn.createStatement(); stmt.e*ecuteUpdate(sql); conn.mit();returntrue;}catch(E*ceptione){ System.out.println("e*ecuteSql----"+e.toString());returnfalse;}}}classstuMainFramee*tendsJFrameimplementsActionListener{JMenuBarjmb=newJMenuBar();Message=newJMenu("信息"); JMenuScore=newJMenu("查询"); JMenuItemItem1=newJMenuItem("添加学生信息"); JMenuItemmName=newJMenuItem("学生成绩查询"); JMenuItemmScore=newJMenuItem("按成绩查询"); JMenuItemmNam1=newJMenuItem("查询学生信息"); JLabellabel=newJLabel();publicstuMainFrame(){ImageIconicon=newImageIcon("src/images/1.jpg");label.setIcon(icon);label.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());add(label); setSize(label.getWidth(),label.getHeight());this.setJMenuBar(jmb);jmb.add(Message);jmb.add(Score);Message.add(Item1);Score.add(mNam1);Score.add(mName);Score.add(mScore);Item1.addActionListener(this);mName.addActionListener(this);mScore.addActionListener(this);mNam1.addActionListener(this);}publicvoidactionPerformed(ActionEvente) {if(e.getSource()==Item1) {newaddForm().setVisible(true);}elseif(e.getSource()==mName) {dispose();newScore1().setVisible(true);}elseif(e.getSource()==mScore) {newscoreQueryForm().setVisible(true);} elseif(e.getSource()==mNam1) {dispose();newSerch1().setVisible(true);}}}classmainFramee*tendsJFrameimplementsActionListener{ JLabellabel=newJLabel(); JMenuBarmBar=newJMenuBar(); JPanelp=newJPanel();privateJMenumSystem,mOperate,mQuery,mHelp,myMenuUser;privateJMenuItemmFile,mNew,mOpen,mE*it,mAdd,mDel,mModify,mName,miShow,mScore,mAbout,miUser,mAddSc; publicmainFrame() { this.setJMenuBar(mBar); ImageIconicon=newImageIcon("src/images/1.jpg");label.setIcon(icon);label.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight()); add(label); setSize(label.getWidth(),label.getHeight());myMenuUser=newJMenu("用户");miUser=newJMenuItem("编辑用户");myMenuUser.add(miUser);mSystem=newJMenu("系统");mOperate=newJMenu("数据操作");mQuery=newJMenu("查询");mHelp=newJMenu("帮助");mBar.add(mSystem);mBar.add(mOperate);mBar.add(mQuery);mBar.add(mHelp);mBar.add(myMenuUser);mFile=newJMenuItem("文件");mNew=newJMenuItem("新建");mOpen=newJMenuItem("打开");mE*it=newJMenuItem("退出");mSystem.add(mFile);mSystem.add(mNew);mSystem.add(mOpen);mSystem.addSeparator();mSystem.add(mE*it);mAdd=newJMenuItem("添加基本信息");mAddSc=newJMenuItem("添加成绩信息");mDel=newJMenuItem("删除");mModify=newJMenuItem("修改");mOperate.add(mAdd);mOperate.add(mAddSc);mOperate.add(mDel);mOperate.add(mModify);mName=newJMenuItem("查询学生信息");mScore=newJMenuItem("查询学生成绩");miShow=newJMenuItem("全部显示");mQuery.add(mName);mQuery.add(mScore);mQuery.addSeparator();mQuery.add(miShow);mAbout=newJMenuItem("软件信息");mHelp.add(mAbout);mE*it.addActionListener(this);mAdd.addActionListener(this);mDel.addActionListener(this);mModify.addActionListener(this);mName.addActionListener(this);mScore.addActionListener(this);mAbout.addActionListener(this);miShow.addActionListener(this);miUser.addActionListener(this);mAddSc.addActionListener(this);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==mE*it){ dispose();newCJ().setVisible(true);}elseif(e.getSource()==mAbout){ JOptionPane.showMessageDialog(this,"学生成绩管理系统\n\n电信学院\n\n2012年3月","软件信息",JOptionPane.INFORMATION_MESSAGE);}elseif(e.getSource()==mAdd){ dispose();newaddForm().setVisible(true);}elseif(e.getSource()==mAddSc){ dispose();newaddScore().setVisible(true);}elseif(e.getSource()==mDel){ dispose();newdeleteForm().setVisible(true);}elseif(e.getSource()==mName){ dispose();newSerch().setVisible(true);}elseif(e.getSource()==mScore){ dispose();newScore().setVisible(true);}elseif(e.getSource()==mModify){newmodifyForm().setVisible(true);}elseif(e.getSource()==miUser){newuserFrame().setVisible(true);}elseif(e.getSource()==miShow){newfreshTable().setVisible(true);}}}classCJe*tendsJFrameimplementsActionListener{ JLabelt1=newJLabel("ID号:"); JLabelt3=newJLabel("密码:"); JLabellabel=newJLabel();publicStringzh=null; JTe*tFieldt2=newJTe*tField(null,15); JTe*tFieldt4=newJPasswordField(null,15); JRadioButtonb=newJRadioButton("教师"); JRadioButtonb1=newJRadioButton("学生"); utton1=newutton("登录"); utton2=newutton("取消");publicCJ(){super("学生生成绩管理系统"); setLayout(null);1.setBounds(110,170,60,20);1.setBackground(Color.red); add(1);2.setBounds(210,170,60,20);2.setBackground(Color.red); add(2);t1.setBounds(90,50,80,35); add(t1);t2.setBounds(120,50,150,35); add(t2);t3.setBounds(90,100,80,35); add(t3);t4.setBounds(120,100,150,35); add(t4);b.setBounds(200,20,70,30);b1.setBounds(120,20,70,30); ButtonGroupbg=newButtonGroup();b.setSelected(false);b1.setSelected(true);b1.setSelected(false); add(b);bg.add(b);add(b1);bg.add(b1);b.setContentAreaFilled(false);b1.setContentAreaFilled(false);ImageIconicon=newImageIcon("src/images/a.jpg");label.setIcon(icon);label.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());add(label);setSize(label.getWidth(),label.getHeight());setResizable(false);setVisible(true);setLocation(300,300);setDefaultCloseOperation(JFrame.E*IT_ON_CLOSE);1.addActionListener(this);2.addActionListener(this);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==2){ System.e*it(0);}elseif(e.getSource()==1){ Stringusername,password; username=t2.getTe*t(); password=t4.getTe*t();if(b.isSelected()){if(username.toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入用户名","温馨提示",JOptionPane.INFORMATION_MESSAGE); }elseif(password.toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入密码","温馨提示",JOptionPane.INFORMATION_MESSAGE); }else{ myConnectionconn=newmyConnection(); ResultSetrs; String sql="select*from教师信息表where教师ID='"+username.toString()+"'and登录密码='"+password.toString()+"'";try{ rs=conn.getResult(sql); rs.last();if(rs.getRow()==1) {setVisible(false); rs.beforeFirst();while(rs.ne*t()){this.dispose(); sql="select*from学籍信息表"; mainFramemf=newmainFrame(); mf.setLayout(null); mf.setVisible(true); mf.setLocation(300,300); mf.setResizable(false); mf.setTitle("学生成绩管理系统:教师登录界面"); mf.setDefaultCloseOperation(JFrame.E*IT_ON_CLOSE); mf.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){ System.e*it(0); } }); JOptionPane.showMessageDialog(null,rs.getString("教师")+"老师!您好!欢迎登录学生成绩管理系统!");} }else{ JOptionPane.showMessageDialog(null,"用户名或密码错误","登录失败",JOptionPane.INFORMATION_MESSAGE); } }catch(E*ceptioner){ System.out.println(er.toString()); }} }if(b1.isSelected()){if(username.toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入用户名","温馨提示",JOptionPane.INFORMATION_MESSAGE); }elseif(password.toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入密码","温馨提示",JOptionPane.INFORMATION_MESSAGE); }else{ myConnectionconn=newmyConnection(); ResultSetrs; String sql="select*from学籍信息表where**='"+t2.getTe*t().toString()+"'and登录密码='"+t4.getTe*t().toString()+"'";try{ rs=conn.getResult(sql); rs.last();if(rs.getRow()==1) {setVisible(false); rs.beforeFirst();while(rs.ne*t()){this.dispose(); sql="select*from学籍信息表"; stuMainFramesmf=newstuMainFrame(); smf.setSize(500,400); smf.setVisible(true); smf.setResizable(false); smf.setDefaultCloseOperation(JFrame.E*IT_ON_CLOSE); smf.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){ System.e*it(0); } }); JOptionPane.showMessageDialog(null,rs.getString("学生")+"同学!您好!欢迎登录学生成绩管理系统!");}}else{ JOptionPane.showMessageDialog(null,"用户名或密码错误","登录失败",JOptionPane.INFORMATION_MESSAGE); }}catch(E*ceptioner){ System.out.println(er.toString()); }}}}}publicstaticvoidmain(String[]args){try{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(E*ceptione){} CJframe=newCJ();newmainFrame(); stuMainFramestu=newstuMainFrame();}}2.添加学生基本信息importjava*.swing.*;import;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;publicclassaddForme*tendsJFrameimplementsActionListener{JLabellabel1=newJLabel("添加基本信息",JLabel.CENTER); JLabellab*uehao=newJLabel("**:",JLabel.CENTER); JLabellabyear=newJLabel("年龄:",JLabel.CENTER); JLabellabName=newJLabel(":",JLabel.CENTER);JLabellabDate=newJLabel("出生日期:",JLabel.CENTER);JLabellabclass=newJLabel("班级:",JLabel.CENTER);JLabellabzy=newJLabel("专业:",JLabel.CENTER);JLabellabmz=newJLabel("民族:",JLabel.CENTER);JLabellabse*=newJLabel("性别:",JLabel.CENTER);JTe*tFieldt*tName=newJTe*tField(20);JTe*tFieldt*tDate=newJTe*tField(18);JTe*tFieldt*t*ueHao=newJTe*tField(20);JTe*tFieldt*tYear=newJTe*tField(20);JTe*tFieldt*tClass=newJTe*tField(20);JTe*tFieldt*tZY=newJTe*tField(20);JTe*tFieldt*tMZ=newJTe*tField(20);ButtonGroupbgp=newButtonGroup(); JRadioButtonman=newJRadioButton("男"); JRadioButtonwomen=newJRadioButton("女");uttonbtnAdd=newutton("添加");uttonbtnCancel=newutton("返回");uttonbtnReset=newutton("重置");JPaneljpl=newJPanel();//创建面板对象Connectioncon;Statementsql;ResultSetrs;addForm(){ super("添加学生信息");this.setResizable(false);this.setSize(550,450);this.setVisible(true);this.setLocation(300,300);this.setDefaultCloseOperation(JFrame.E*IT_ON_CLOSE);this.add(jpl);jpl.setLayout(null);btnAdd.addActionListener(this);btnReset.addActionListener(this);btnCancel.addActionListener(this);jpl.setBackground(Color.cyan);man.setBackground(Color.cyan);women.setBackground(Color.cyan);label1.setBounds(100,20,300,20);jpl.add(label1);lab*uehao.setBounds(100,50,70,20);jpl.add(lab*uehao);t*t*ueHao.setBounds(190,50,140,20);jpl.add(t*t*ueHao);labName.setBounds(100,90,70,20);jpl.add(labName);t*tName.setBounds(190,90,140,20);jpl.add(t*tName);labse*.setBounds(110,130,60,20);jpl.add(labse*);man.setBounds(190,130,60,20);women.setBounds(270,130,60,20);jpl.add(man);jpl.add(women);bgp.add(man);bgp.add(women);labyear.setBounds(100,180,70,20);jpl.add(labyear);t*tYear.setBounds(190,180,140,20);jpl.add(t*tYear);labDate.setBounds(100,210,70,20);jpl.add(labDate);t*tDate.setBounds(190,210,140,20);jpl.add(t*tDate);labmz.setBounds(100,240,70,20);jpl.add(labmz);t*tMZ.setBounds(190,240,140,20);jpl.add(t*tMZ); labclass.setBounds(100,270,70,20);jpl.add(labclass);t*tClass.setBounds(190,270,140,20);jpl.add(t*tClass);labzy.setBounds(100,300,70,20);jpl.add(labzy);t*tZY.setBounds(190,300,140,20);jpl.add(t*tZY);btnReset.setBounds(80,350,90,20);btnAdd.setBounds(200,350,90,20);btnCancel.setBounds(320,350,90,20);jpl.add(btnReset);jpl.add(btnAdd);jpl.add(btnCancel);}publicvoidactionPerformed(ActionEvente) { if(e.getSource()==btnCancel){ dispose();newmainFrame().setVisible(true);}if(e.getSource()==btnAdd) {if(t*t*ueHao.getTe*t().toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入**","温馨提示",JOptionPane.INFORMATION_MESSAGE); }elseif(t*tName.getTe*t().toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入","温馨提示",JOptionPane.INFORMATION_MESSAGE); }elseif(t*tYear.getTe*t().toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入年龄","温馨提示",JOptionPane.INFORMATION_MESSAGE); }elseif(t*tDate.getTe*t().toString().equals("")){ JOptionPane.showMessageDialog(null,"出生日期","温馨提示",JOptionPane.INFORMATION_MESSAGE); }elseif(t*tZY.getTe*t().toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入专业","温馨提示",JOptionPane.INFORMATION_MESSAGE); }elseif(t*tMZ.getTe*t().toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入民族","温馨提示",JOptionPane.INFORMATION_MESSAGE); }elseif(t*tClass.getTe*t().toString().equals("")){ JOptionPane.showMessageDialog(null,"请输入班级","温馨提示",JOptionPane.INFORMATION_MESSAGE);}else{ Stringse*;if(man.isSelected()) {se*="男";}else {se*="女";}try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundE*ceptionce) {JOptionPane.showMessageDialog(null,ce.getMessage());}try{ Connectioncon=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123"); Statementstmt=con.createStatement();inta=stmt.e*ecuteUpdate("insertinto学籍信息表(**,登录密码,,年龄,出生日期,性别,班级,专业,民族)values('"+t*t*ueHao.getTe*t()+"','"+00000+"','"+t*tName.getTe*t()+"','"+t*tYear.getTe*t()+"','"+t*tDate.getTe*t()+"','"+se*+"','"+t*tClass.getTe*t()+"','"+t*tZY.getTe*t()+"','"+t*tMZ.getTe*t()+"')");if(a==1) {JOptionPane.showMessageDialog(null,"已成功添加","温馨提示",JOptionPane.INFORMATION_MESSAGE);}else {JOptionPane.showMessageDialog(null,"添加失败","温馨提示",JOptionPane.INFORMATION_MESSAGE);} stmt.close();}catch(SQLE*ceptionse) {JOptionPane.showMessageDialog(null,se.getMessage());}}}else{t*tClass.setTe*t("");t*tZY.setTe*t("");t*tMZ.setTe*t("");t*tName.setTe*t("");t*tDate.setTe*t("");t*t*ueHao.setTe*t("");t*tYear.setTe*t("");t*t*ueHao.requestFocus();}}publicstaticvoidmain(String[]args) {addFormamg=newaddForm();}}3.添加学生成绩importjava.awt.*;importjava*.swing.*;importjava.awt.event.*;importjava.sql.*;publicclassaddScoree*tendsJFrameimplementsActionListener{staticaddScoress; JLabel[]label={newJLabel("**:"),newJLabel("计算机网络:"),newJLabel("Linu*操作系统:"),newJLabel("计算机专业英语:"),newJLabel("计算机信息技术基础:"),newJLabel("Java程序设计:"),newJLabel("数据库应用实训教程:"),newJLabel("高等数学:"),newJLabel("*ML:")}; JTe*tField[]t*t={newJTe*tField(),newJTe*tField(),newJTe*tField(),newJTe*tField(),newJTe*tField(),newJTe*tField(),newJTe*tField(),newJTe*tField(),newJTe*tField()}; uttonadd=newutton("添加"); uttonreset=newutton("重置"); uttonCancel=newutton("返回"); JPaneljpl=newJPanel(); JLabeltitle=newJLabel("添加学生成绩",JLabel.CENTER); Fontf=newFont("黑体",Font.BOLD,16);ints=100;publicaddScore() {super("添加学生信息");this.setResizable(false);this.setSize(500,600);this.setDefaultCloseOperation(E*IT_ON_CLOSE);this.setVisible(true);this.add(jpl);Cancel.addActionListener(this);add.addActionListener(this);reset.addActionListener(this);jpl.setLayout(null);title.setBounds(150,40,200,20);title.setFont(f);title.setForeground(Color.red);jpl.setBackground(Color.LIGHT_GRAY);jpl.add(title);for(inti=0;i<label.length;i++) {label[i].setBounds(100,s,140,20);jpl.add(label[i]);t*t[i].setBounds(260,s,140,20);jpl.add(t*t[i]);s=s+40; }add.setBounds(100,s,80,20);reset.setBounds(200,s,80,20);Cancel.setBounds(300,s,80,20);jpl.add(add);jpl.add(reset);jpl.add(Cancel); }publicvoidactionPerformed(ActionEvente) {if(e.getSource()==Cancel){ dispose();newmainFrame().setVisible(true); }elseif(e.getSource()==add) {try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundE*ceptionce) {JOptionPane.showMessageDialog(ss,ce.getMessage());}try{Connectioncon=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123"); Statementstmt=con.createStatement();inta=stmt.e*ecuteUpdate("insertinto成绩信息表(**,计算机网络,Linu*操作系统,计算机专业英语,计算机信息技术基础,Java程序设计,数据库应用实训教程,高等数学,*ml)values('"+t*t[0].getTe*t()+"','"+t*t[1].getTe*t()+"','"+t*t[2].getTe*t()+"','"+t*t[3].getTe*t()+"','"+t*t[4].getTe*t()+"','"+t*t[5].getTe*t()+"','"+t*t[6].getTe*t()+"','"+t*t[7].getTe*t()+"','"+t*t[8].getTe*t()+"')");if(a==1) {JOptionPane.showMessageDialog(ss,"添加成功");}else {JOptionPane.showMessageDialog(ss,"添加失败");}}catch(SQLE*ceptionse) {JOptionPane.showMessageDialog(ss,se.getMessage()); }}else {for(inti=0;i<t*t.length;i++) {t*t[i].setTe*t("");t*t[0].requestFocus(); }}}publicstaticvoidmain(String[]args) {addScoreas=newaddScore();}}4.修改学生信息:importjava*.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;publicclassmodifyForme*tendsJFrameimplementsActionListener{ JPaneljpl=newJPanel(); JLabelSCH=newJLabel("修改学生信息",JLabel.CENTER); Fontf=newFont("楷体",Font.BOLD+Font.ITALIC,30); JLabellabel1=newJLabel("请输入**:",JLabel.CENTER); uttonbtnQuery=newutton("查询"); JLabellabel2=newJLabel(":",JLabel.CENTER); JLabellabyear=newJLabel("年龄:",JLabel.CENTER); JLabellabDate=newJLabel("出生日期:",JLabel.CENTER); JLabellabel5=newJLabel("性别:",JLabel.CENTER); JLabellabel3=newJLabel("班级:",JLabel.CENTER); JLabellabel4=newJLabel("专业:",JLabel.CENTER);JLabellabmz=newJLabel("民族:",JLabel.CENTER); ButtonGroupbgp=newButtonGroup(); JRadioButtonman=newJRadioButton("男"); JRadioButtonwomen=newJRadioButton("女"); JTe*tFieldtyear=newJTe*tField(); JTe*tFieldtDate=newJTe*tField(); JTe*tFieldtmz=newJTe*tField(); JTe*tFieldnum=newJTe*tField(); JTe*tFieldnam=newJTe*tField(); JTe*tFieldclas=newJTe*tField(); JTe*tFieldscl=newJTe*tField(); uttonbtnModify=newutton("修改"); uttonbtnCancel=newutton("取消"); Connectioncon;Statementsql;ResultSetrs;intre;publicmodifyForm() {this.setSize(560,460);this.setVisible(true);this.setResizable(false);SCH.setForeground(Color.red);this.setDefaultCloseOperation(JFrame.E*IT_ON_CLOSE);this.add(jpl);jpl.setBackground(Color.cyan);man.setBackground(Color.cyan);women.setBackground(Color.cyan);jpl.setLayout(null);btnQuery.addActionListener(this);btnModify.addActionListener(this);btnCancel.addActionListener(this);SCH.setBounds(100,20,300,20);jpl.add(SCH);label1.setBounds(100,60,100,20);jpl.add(label1);num.setBounds(220,60,140,20);jpl.add(num);btnQuery.setBounds(120,100,90,20);btnModify.setBounds(230,100,90,20);btnCancel.setBounds(340,100,90,20);jpl.add(btnQuery);jpl.add(btnModify);jpl.add(btnCancel);label2.setBounds(100,150,70,20);jpl.add(label2);nam.setBounds(190,150,140,20);jpl.add(nam);labyear.setBounds(100,180,70,20);jpl.add(labyear);tyear.setBounds(190,180,140,20);jpl.add(tyear);labDate.setBounds(100,210,70,20);jpl.add(labDate);tDate.setBounds(190,210,140,20);jpl.add(tDate);label5.setBounds(100,250,70,20);jpl.add(label5);man.setBounds(205,250,60,20);women.setBounds(285,250,60,20);bgp.add(man);bgp.add(women);jpl.add(man);jpl.add(women);label3.setBounds(100,290,70,20);jpl.add(label3);clas.setBounds(190,290,140,20);jpl.add(clas);label4.setBounds(100,320,70,20);jpl.add(label4);scl.setBounds(190,320,140,20);jpl.add(scl);labmz.setBounds(100,350,70,20);jpl.add(labmz);tmz.setBounds(190,350,140,20);jpl.add(tmz);}publicvoidactionPerformed(ActionEventae){if(ae.getSource()==btnCancel){dispose();newmainFrame().setVisible(true);}elseif(ae.getSource()==btnQuery){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundE*ceptione){}try{con=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123");sql=con.createStatement();rs=sql.e*ecuteQuery("select*from学籍信息表where**='"+num.getTe*t()+"'");if(rs.ne*t()){num.setTe*t(rs.getString("**"));nam.setTe*t(rs.getString(""));tyear.setTe*t(rs.getString("年龄").toString());tDate.setTe*t(rs.getString("出生日期"));if(rs.getString("性别").equals("男")) {man.setSelected(true);}else {women.setSelected(true);}clas.setTe*t(rs.getString("班级"));scl.setTe*t(rs.getString("专业"));tmz.setTe*t(rs.getString("民族"));btnModify.setEnabled(true);nam.setEditable(true);tyear.setEditable(true);tDate.setEditable(true);clas.setEditable(true);scl.setEditable(true);tmz.setEditable(true);}else{ JOptionPane.showMessageDialog(null,"不存在该记录!","温馨提示",JOptionPane.INFORMATION_MESSAGE);btnModify.setEnabled(false);tyear.setTe*t("");tDate.setTe*t("");tmz.setTe*t("");num.setTe*t("");nam.setTe*t("");clas.setTe*t("");scl.setTe*t("");num.requestFocus();nam.setEditable(false);tyear.setEditable(false);tDate.setEditable(false);clas.setEditable(false);scl.setEditable(false);tmz.setEditable(false);}}catch(SQLE*ceptione){}}elseif(ae.getSource()==btnModify){try{con=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123");sql=con.createStatement();re=sql.e*ecuteUpdate("Update学籍信息表set='"+nam.getTe*t()+"',年龄='"+tyear.getTe*t()+"',出生日期='"+tDate.getTe*t()+"',班级='"+clas.getTe*t()+"',专业='"+scl.getTe*t()+"',民族='"+tmz.getTe*t()+"'where**='"+num.getTe*t()+"'");if(re==1) {JOptionPane.showMessageDialog(null,"记录修改完毕!","温馨提示",JOptionPane.INFORMATION_MESSAGE);}else {JOptionPane.showMessageDialog(null,"记录修改失败!","温馨提示",JOptionPane.INFORMATION_MESSAGE);}sql.close();}catch(SQLE*ceptionse) {JOptionPane.showMessageDialog(null,se.getMessage());}}else{btnModify.setEnabled(false);tyear.setTe*t("");tDate.setTe*t("");tmz.setTe*t("");num.setTe*t("");nam.setTe*t("");clas.setTe*t("");scl.setTe*t("");num.requestFocus();nam.setEditable(false);tyear.setEditable(false);tDate.setEditable(false);clas.setEditable(false);scl.setEditable(false);tmz.setEditable(false);}}publicstaticvoidmain(String[]args){newmodifyForm();}}5.删除学生信息importjava*.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;publicclassdeleteForme*tendsJFrameimplementsActionListener{JPaneljpl=newJPanel(); JLabelSCH=newJLabel("删除学生信息",JLabel.CENTER); Fontf=newFont("楷体",Font.BOLD+Font.ITALIC,30); JLabellabel1=newJLabel("请输入**:",JLabel.CENTER); uttonbtnQuery=newutton("查询"); JLabellabel2=newJLabel(":",JLabel.CENTER); JLabellabyear=newJLabel("年龄:",JLabel.CENTER); JLabellabDate=newJLabel("出生日期:",JLabel.CENTER); JLabellabel5=newJLabel("性别:",JLabel.CENTER); JLabellabel3=newJLabel("班级:",JLabel.CENTER); JLabellabel4=newJLabel("专业:",JLabel.CENTER);JLabellabmz=newJLabel("民族:",JLabel.CENTER); ButtonGroupbgp=newButtonGroup(); JRadioButtonman=newJRadioButton("男"); JRadioButtonwomen=newJRadioButton("女"); JTe*tFieldtyear=newJTe*tField(); JTe*tFieldtDate=newJTe*tField(); JTe*tFieldtmz=newJTe*tField(); JTe*tFieldnum=newJTe*tField(); JTe*tFieldnam=newJTe*tField(); JTe*tFieldclas=newJTe*tField(); JTe*tFieldscl=newJTe*tField(); uttonbtnDelete=newutton("删除"); uttonbtnCancel=newutton("取消");Connectioncon;Statementsql;ResultSetrs;intre;deleteForm(){ this.setSize(560,460);this.setVisible(true);this.setResizable(false);SCH.setForeground(Color.red);this.setDefaultCloseOperation(JFrame.E*IT_ON_CLOSE);this.add(jpl);jpl.setBackground(Color.cyan);man.setBackground(Color.cyan);women.setBackground(Color.cyan);jpl.setLayout(null);btnQuery.addActionListener(this);btnDelete.addActionListener(this);btnCancel.addActionListener(this);SCH.setBounds(100,20,300,20);jpl.add(SCH);label1.setBounds(100,60,100,20);jpl.add(label1);num.setBounds(220,60,140,20);jpl.add(num);btnQuery.setBounds(120,100,90,20);btnDelete.setBounds(230,100,90,20);btnCancel.setBounds(340,100,90,20);jpl.add(btnQuery);jpl.add(btnDelete);jpl.add(btnCancel);label2.setBounds(100,150,70,20);jpl.add(label2);nam.setBounds(190,150,140,20);jpl.add(nam);labyear.setBounds(100,180,70,20);jpl.add(labyear);tyear.setBounds(190,180,140,20);jpl.add(tyear);labDate.setBounds(100,210,70,20);jpl.add(labDate);tDate.setBounds(190,210,140,20);jpl.add(tDate);label5.setBounds(100,250,70,20);jpl.add(label5);man.setBounds(205,250,60,20);women.setBounds(285,250,60,20);bgp.add(man);bgp.add(women);jpl.add(man);jpl.add(women);label3.setBounds(100,290,70,20);jpl.add(label3);clas.setBounds(190,290,140,20);jpl.add(clas);label4.setBounds(100,320,70,20);jpl.add(label4);scl.setBounds(190,320,140,20);jpl.add(scl);labmz.setBounds(100,350,70,20);jpl.add(labmz);tmz.setBounds(190,350,140,20);jpl.add(tmz);btnDelete.setEnabled(false);//取消删除按钮的功能nam.setEditable(false);tyear.setEditable(false);tDate.setEditable(false);clas.setEditable(false);scl.setEditable(false);tmz.setEditable(false);setVisible(true);num.requestFocus();}publicvoidactionPerformed(ActionEventae){ if(ae.getSource()==btnCancel){dispose();newmainFrame().setVisible(true);}elseif(ae.getSource()==btnQuery){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundE*ceptione){}try{con=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123");sql=con.createStatement();rs=sql.e*ecuteQuery("select*from学籍信息表where**='"+num.getTe*t()+"'");if(rs.ne*t()){num.setTe*t(rs.getString("**"));nam.setTe*t(rs.getString(""));tyear.setTe*t(rs.getString("年龄").toString());tDate.setTe*t(rs.getString("出生日期"));if(rs.getString("性别").equals("男")) {man.setSelected(true);}else {women.setSelected(true);}clas.setTe*t(rs.getString("班级"));scl.setTe*t(rs.getString("专业"));tmz.setTe*t(rs.getString("民族"));btnDelete.setEnabled(true);nam.setEditable(true);tyear.setEditable(true);tDate.setEditable(true);clas.setEditable(true);scl.setEditable(true);tmz.setEditable(true);}else{JOptionPane.showMessageDialog(null,"不存在该记录!","温馨提示",JOptionPane.INFORMATION_MESSAGE);btnDelete.setEnabled(false);tyear.setTe*t("");tDate.setTe*t("");tmz.setTe*t("");num.setTe*t("");nam.setTe*t("");clas.setTe*t("");scl.setTe*t("");num.requestFocus();nam.setEditable(false);tyear.setEditable(false);tDate.setEditable(false);clas.setEditable(false);scl.setEditable(false);tmz.setEditable(false);}}catch(SQLE*ceptione){}}elseif(ae.getSource()==btnDelete) //实现删除功能{try{con=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123");sql=con.createStatement();re=sql.e*ecuteUpdate("DELETEFROM学籍信息表where**=

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论