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

下载本文档

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

文档简介

/《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,Xmlsmallint,>概要结构分析:学生成绩管理系统登录界面学生成绩管理系统登录界面添加学生信息查看学生成绩查看学生信息查看学生成绩查看学生信息删除学生信息修改学生信息添加学生成绩添加学生信息学生登录教师登录添加学生信息查看学生成绩查看学生信息查看学生成绩查看学生信息删除学生信息修改学生信息添加学生成绩添加学生信息学生登录教师登录1.登录界面和主界面importjavax.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.executeQuery<sql>;returnre;}catch<Exceptione>{ System.out.println<"getResult"+e.toString<>>;returnnull;}}publicbooleanexecuteSql<Stringsql>{try{Class.forName<"sun.jdbc.odbc.JdbcOdbcDriver">; Connectionconn=DriverManager.getConnection<"jdbc:odbc:学生成绩管理系统","ww","123">; Statementstmt=conn.createStatement<>; stmt.executeUpdate<sql>; mit<>;returntrue;}catch<Exceptione>{ System.out.println<"executeSql"+e.toString<>>;returnfalse;}}}classstuMainFrameextendsJFrameimplementsActionListener{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>;}}}classmainFrameextendsJFrameimplementsActionListener{ JLabellabel=newJLabel<>; JMenuBarmBar=newJMenuBar<>; JPanelp=newJPanel<>;privateJMenumSystem,mOperate,mQuery,mHelp,myMenuUser;privateJMenuItemmFile,mNew,mOpen,mExit,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<"打开">;mExit=newJMenuItem<"退出">;mSystem.add<mFile>;mSystem.add<mNew>;mSystem.add<mOpen>;mSystem.addSeparator<>;mSystem.add<mExit>;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>;mExit.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<>==mExit>{ dispose<>;newCJ<>.setVisible<true>;}elseif<e.getSource<>==mAbout>{ JOptionPane.showMessageDialog<this,"学生成绩管理系统\n\n电信学院\n\n20XX3月","软件信息",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>;}}}classCJextendsJFrameimplementsActionListener{ JLabelt1=newJLabel<"ID号:">; JLabelt3=newJLabel<"密码:">; JLabellabel=newJLabel<>;publicStringzh=null; JTextFieldt2=newJTextField<null,15>; JTextFieldt4=newJPasswordField<null,15>; JRadioButtonb=newJRadioButton<"教师">; JRadioButtonb1=newJRadioButton<"学生">; JButtonjB1=newJButton<"登录">; JButtonjB2=newJButton<"取消">;publicCJ<>{super<"学生生成绩管理系统">; setLayout<null>;jB1.setBounds<110,170,60,20>;jB1.setBackground<Color.red>; add<jB1>;jB2.setBounds<210,170,60,20>;jB2.setBackground<Color.red>; add<jB2>;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.EXIT_ON_CLOSE>;jB1.addActionListener<this>;jB2.addActionListener<this>;}publicvoidactionPerformed<ActionEvente>{if<e.getSource<>==jB2>{ System.exit<0>;}elseif<e.getSource<>==jB1>{ Stringusername,password; username=t2.getText<>; password=t4.getText<>;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.next<>>{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.EXIT_ON_CLOSE>; mf.addWindowListener<newWindowAdapter<>{publicvoidwindowClosing<WindowEvente>{ System.exit<0>; } }>; JOptionPane.showMessageDialog<null,rs.getString<"教师姓名">+"老师!您好!欢迎登录学生成绩管理系统!">;} }else{ JOptionPane.showMessageDialog<null,"用户名或密码错误","登录失败",JOptionPane.INFORMATION_MESSAGE>; } }catch<Exceptioner>{ 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.getText<>.toString<>+"'and登录密码='"+t4.getText<>.toString<>+"'";try{ rs=conn.getResult<sql>; rs.last<>;if<rs.getRow<>==1> {setVisible<false>; rs.beforeFirst<>;while<rs.next<>>{this.dispose<>; sql="select*from学籍信息表"; stuMainFramesmf=newstuMainFrame<>; smf.setSize<500,400>; smf.setVisible<true>; smf.setResizable<false>; smf.setDefaultCloseOperation<JFrame.EXIT_ON_CLOSE>; smf.addWindowListener<newWindowAdapter<>{publicvoidwindowClosing<WindowEvente>{ System.exit<0>; } }>; JOptionPane.showMessageDialog<null,rs.getString<"学生姓名">+"同学!您好!欢迎登录学生成绩管理系统!">;}}else{ JOptionPane.showMessageDialog<null,"用户名或密码错误","登录失败",JOptionPane.INFORMATION_MESSAGE>; }}catch<Exceptioner>{ System.out.println<er.toString<>>; }}}}}publicstaticvoidmain<String[]args>{try{ UIManager.setLookAndFeel<UIManager.getSystemLookAndFeelClassName<>>; }catch<Exceptione>{} CJframe=newCJ<>;newmainFrame<>; stuMainFramestu=newstuMainFrame<>;}}2.添加学生基本信息importjavax.swing.*;import;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;publicclassaddFormextendsJFrameimplementsActionListener{JLabellabel1=newJLabel<"添加基本信息",JLabel.CENTER>; JLabellabxuehao=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>;JLabellabsex=newJLabel<"性别:",JLabel.CENTER>;JTextFieldtxtName=newJTextField<20>;JTextFieldtxtDate=newJTextField<18>;JTextFieldtxtXueHao=newJTextField<20>;JTextFieldtxtYear=newJTextField<20>;JTextFieldtxtClass=newJTextField<20>;JTextFieldtxtZY=newJTextField<20>;JTextFieldtxtMZ=newJTextField<20>;ButtonGroupbgp=newButtonGroup<>; JRadioButtonman=newJRadioButton<"男">; JRadioButtonwomen=newJRadioButton<"女">;JButtonbtnAdd=newJButton<"添加">;JButtonbtnCancel=newJButton<"返回">;JButtonbtnReset=newJButton<"重置">;JPaneljpl=newJPanel<>;//创建面板对象Connectioncon;Statementsql;ResultSetrs;addForm<>{ super<"添加学生信息">;this.setResizable<false>;this.setSize<550,450>;this.setVisible<true>;this.setLocation<300,300>;this.setDefaultCloseOperation<JFrame.EXIT_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>;labxuehao.setBounds<100,50,70,20>;jpl.add<labxuehao>;txtXueHao.setBounds<190,50,140,20>;jpl.add<txtXueHao>;labName.setBounds<100,90,70,20>;jpl.add<labName>;txtName.setBounds<190,90,140,20>;jpl.add<txtName>;labsex.setBounds<110,130,60,20>;jpl.add<labsex>;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>;txtYear.setBounds<190,180,140,20>;jpl.add<txtYear>;labDate.setBounds<100,210,70,20>;jpl.add<labDate>;txtDate.setBounds<190,210,140,20>;jpl.add<txtDate>;labmz.setBounds<100,240,70,20>;jpl.add<labmz>;txtMZ.setBounds<190,240,140,20>;jpl.add<txtMZ>; labclass.setBounds<100,270,70,20>;jpl.add<labclass>;txtClass.setBounds<190,270,140,20>;jpl.add<txtClass>;labzy.setBounds<100,300,70,20>;jpl.add<labzy>;txtZY.setBounds<190,300,140,20>;jpl.add<txtZY>;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<txtXueHao.getText<>.toString<>.equals<"">>{ JOptionPane.showMessageDialog<null,"请输入学号","温馨提示",JOptionPane.INFORMATION_MESSAGE>; }elseif<txtName.getText<>.toString<>.equals<"">>{ JOptionPane.showMessageDialog<null,"请输入姓名","温馨提示",JOptionPane.INFORMATION_MESSAGE>; }elseif<txtYear.getText<>.toString<>.equals<"">>{ JOptionPane.showMessageDialog<null,"请输入年龄","温馨提示",JOptionPane.INFORMATION_MESSAGE>; }elseif<txtDate.getText<>.toString<>.equals<"">>{ JOptionPane.showMessageDialog<null,"出生日期","温馨提示",JOptionPane.INFORMATION_MESSAGE>; }elseif<txtZY.getText<>.toString<>.equals<"">>{ JOptionPane.showMessageDialog<null,"请输入专业","温馨提示",JOptionPane.INFORMATION_MESSAGE>; }elseif<txtMZ.getText<>.toString<>.equals<"">>{ JOptionPane.showMessageDialog<null,"请输入民族","温馨提示",JOptionPane.INFORMATION_MESSAGE>; }elseif<txtClass.getText<>.toString<>.equals<"">>{ JOptionPane.showMessageDialog<null,"请输入班级","温馨提示",JOptionPane.INFORMATION_MESSAGE>;}else{ Stringsex;if<man.isSelected<>> {sex="男";}else {sex="女";}try {Class.forName<"sun.jdbc.odbc.JdbcOdbcDriver">;}catch<ClassNotFoundExceptionce> {JOptionPane.showMessageDialog<null,ce.getMessage<>>;}try{ Connectioncon=DriverManager.getConnection<"jdbc:odbc:学生成绩管理系统","ww","123">; Statementstmt=con.createStatement<>;inta=stmt.executeUpdate<"insertinto学籍信息表<学号,登录密码,姓名,年龄,出生日期,性别,班级,专业,民族>values<'"+txtXueHao.getText<>+"','"+00000+"','"+txtName.getText<>+"','"+txtYear.getText<>+"','"+txtDate.getText<>+"','"+sex+"','"+txtClass.getText<>+"','"+txtZY.getText<>+"','"+txtMZ.getText<>+"'>">;if<a==1> {JOptionPane.showMessageDialog<null,"已成功添加","温馨提示",JOptionPane.INFORMATION_MESSAGE>;}else {JOptionPane.showMessageDialog<null,"添加失败","温馨提示",JOptionPane.INFORMATION_MESSAGE>;} stmt.close<>;}catch<SQLExceptionse> {JOptionPane.showMessageDialog<null,se.getMessage<>>;}}}else{txtClass.setText<"">;txtZY.setText<"">;txtMZ.setText<"">;txtName.setText<"">;txtDate.setText<"">;txtXueHao.setText<"">;txtYear.setText<"">;txtXueHao.requestFocus<>;}}publicstaticvoidmain<String[]args> {addFormamg=newaddForm<>;}}3.添加学生成绩importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjava.sql.*;publicclassaddScoreextendsJFrameimplementsActionListener{staticaddScoress; JLabel[]label={newJLabel<"学号:">,newJLabel<"计算机网络:">,newJLabel<"Linux操作系统:">,newJLabel<"计算机专业英语:">,newJLabel<"计算机信息技术基础:">,newJLabel<"Java程序设计:">,newJLabel<"数据库应用实训教程:">,newJLabel<"高等数学:">,newJLabel<"XML:">}; JTextField[]txt={newJTextField<>,newJTextField<>,newJTextField<>,newJTextField<>,newJTextField<>,newJTextField<>,newJTextField<>,newJTextField<>,newJTextField<>}; JButtonadd=newJButton<"添加">; JButtonreset=newJButton<"重置">; JButtonCancel=newJButton<"返回">; JPaneljpl=newJPanel<>; JLabeltitle=newJLabel<"添加学生成绩",JLabel.CENTER>; Fontf=newFont<"黑体",Font.BOLD,16>;ints=100;publicaddScore<> {super<"添加学生信息">;this.setResizable<false>;this.setSize<500,600>;this.setDefaultCloseOperation<EXIT_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]>;txt[i].setBounds<260,s,140,20>;jpl.add<txt[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<r">;}catch<ClassNotFoundExceptionce> {JOptionPane.showMessageDialog<ss,ce.getMessage<>>;}try{Connectioncon=DriverManager.getConnection<"jdbc:odbc:学生成绩管理系统","ww","123">; Statementstmt=con.createStatement<>;inta=stmt.executeUpdate<"insertinto成绩信息表<学号,计算机网络,Linux操作系统,计算机专业英语,计算机信息技术基础,Java程序设计,数据库应用实训教程,高等数学,Xml>values<'"+txt[0].getText<>+"','"+txt[1].getText<>+"','"+txt[2].getText<>+"','"+txt[3].getText<>+"','"+txt[4].getText<>+"','"+txt[5].getText<>+"','"+txt[6].getText<>+"','"+txt[7].getText<>+"','"+txt[8].getText<>+"'>">;if<a==1> {JOptionPane.showMessageDialog<ss,"添加成功">;}else {JOptionPane.showMessageDialog<ss,"添加失败">;}}catch<SQLExceptionse> {JOptionPane.showMessageDialog<ss,se.getMessage<>>; }}else {for<inti=0;i<txt.length;i++> {txt[i].setText<"">;txt[0].requestFocus<>; }}}publicstaticvoidmain<String[]args> {addScoreas=newaddScore<>;}}4.修改学生信息:importjavax.swing.*;importjava.awt.*;importt.*;importjava.sql.*;publicclassmodifyFormextendsJFrameimplementsActionListener{ JPaneljpl=newJPanel<>; JLabelSCH=newJLabel<"修改学生信息",JLabel.CENTER>; Fontf=newFont<"楷体",Font.BOLD+Font.ITALIC,30>; JLabellabel1=newJLabel<"请输入学号:",JLabel.CENTER>; JButtonbtnQuery=newJButton<"查询">; 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<"女">; JTextFieldtyear=newJTextField<>; JTextFieldtDate=newJTextField<>; JTextFieldtmz=newJTextField<>; JTextFieldnum=newJTextField<>; JTextFieldnam=newJTextField<>; JTextFieldclas=newJTextField<>; JTextFieldscl=newJTextField<>; JButtonbtnModify=newJButton<"修改">; JButtonbtnCancel=newJButton<"取消">; Connectioncon;Statementsql;ResultSetrs;intre;publicmodifyForm<> {this.setSize<560,460>;this.setVisible<true>;this.setResizable<false>;SCH.setForeground<Color.red>;this.setDefaultCloseOperation<JFrame.EXIT_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<ClassNotFoundExceptione>{}try{con=DriverManager.getConnection<"jdbc:odbc:学生成绩管理系统","ww","123">;sql=con.createStatement<>;rs=sql.executeQuery<"select*from学籍信息表where学号='"+num.getText<>+"'">;if<rs.next<>>{num.setText<rs.getString<"学号">>;nam.setText<rs.getString<"姓名">>;tyear.setText<rs.getString<"年龄">.toString<>>;tDate.setText<rs.getString<"出生日期">>;if<rs.getString<"性别">.equals<"男">> {man.setSelected<true>;}else {women.setSelected<true>;}clas.setText<rs.getString<"班级">>;scl.setText<rs.getString<"专业">>;tmz.setText<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.setText<"">;tDate.setText<"">;tmz.setText<"">;num.setText<"">;nam.setText<"">;clas.setText<"">;scl.setText<"">;num.requestFocus<>;nam.setEditable<false>;tyear.setEditable<false>;tDate.setEditable<false>;clas.setEditable<false>;scl.setEditable<false>;tmz.setEditable<false>;}}catch<SQLExceptione>{}}elseif<ae.getSource<>==btnModify>{try{con=DriverManager.getConnection<"jdbc:odbc:学生成绩管理系统","ww","123">;sql=con.createStatement<>;re=sql.executeUpdate<"Update学籍信息表set姓名='"+nam.getText<>+"',年龄='"+tyear.getText<>+"',出生日期='"+tDate.getText<>+"',班级='"+clas.getText<>+"',专业='"+scl.getText<>+"',民族='"+tmz.getText<>+"'where学号='"+num.getText<>+"'">;if<re==1> {JOptionPane.showMessageDialog<null,"记录修改完毕!","温馨提示",JOptionPane.INFORMATION_MESSAGE>;}else {JOptionPane.showMessageDialog<null,"记录修改失败!","温馨提示",JOptionPane.INFORMATION_MESSAGE>;}sql.close<>;}catch<SQLExceptionse> {JOptionPane.showMessageDialog<null,se.getMessage<>>;}}else{btnModify.setEnabled<false>;tyear.setText<"">;tDate.setText<"">;tmz.setText<"">;num.setText<"">;nam.setText<"">;clas.setText<"">;scl.setText<"">;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.删除学生信息importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;publicclassdeleteFormextendsJFrameimplementsActionListener{JPaneljpl=newJPanel<>; JLabelSCH=newJLabel<"删除学生信息",JLabel.CENTER>; Fontf=newFont<"楷体",Font.BOLD+Font.ITALIC,30>; JLabellabel1=newJLabel<"请输入学号:",JLabel.CENTER>; JButtonbtnQuery=newJButton<"查询">; 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<"女">; JTextFieldtyear=newJTextField<>; JTextFieldtDate=newJTextField<>; JTextFieldtmz=newJTextField<>; JTextFieldnum=newJTextField<>; JTextFieldnam=newJTextField<>; JTextFieldclas=newJTextField<>; JTextFieldscl=newJTextField<>; JButtonbtnDelete=newJButton<"删除">; JButtonbtnCancel=newJButton<"取消">;Connectioncon;Statementsql;ResultSetrs;intre;deleteForm<>{ this.setSize<560,460>;this.setVisible<true>;this.setResizable<false>;SCH.setForeground<Color.red>;this.setDefaultCloseOperation<JFrame.EXIT_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<ClassNotFoundExceptione>{}try{con=DriverManager.getConnection<"jdbc:odbc:学生成绩管理系统","ww","123">;sql=con.createStatement<>;rs=sql.executeQuery<"select*from学籍信息表where学号='"+num.getText<>+"'">;if<rs.next<>>{num.setText<rs.getString<"学号">>;nam.setText<rs.getString<"姓名">>;tyear.setText<rs.getString<"年龄">.toString<>>;tDate.setText<rs.getString<"出生日期">>;if<rs.getString<"性别">.equals<"男">> {man.setSelected<true>;}else {women.setSelected<true>;}clas.setText<rs.getString<"班级">>;scl.setText<rs.getString<"专业">>;tmz.setText<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.setText<"">;tDate.setText<"">;tmz.setText<"">;num.setText<"">;nam.setText<"">;clas.setText<"">;scl.setText<"">;num.requestFocus<>;nam.setEditable<false>;tyear.setEditable<false>;tDate.setEditable<false>;clas.setEditable<false>;scl.setEditable<false>;tmz.setEditable<false>;}}catch<SQLExceptione>{}}elseif<ae.getSource<>==btnDelete> //实现删除功能{try{con=DriverManager.getConnection<"jdbc:odbc:学生成绩管理系统","ww","123">;sql=con.createStatement<>;re=sql.executeUpdate<"DE

温馨提示

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

评论

0/150

提交评论