java項目學(xué)生成績管理系統(tǒng)_第1頁
java項目學(xué)生成績管理系統(tǒng)_第2頁
java項目學(xué)生成績管理系統(tǒng)_第3頁
java項目學(xué)生成績管理系統(tǒng)_第4頁
java項目學(xué)生成績管理系統(tǒng)_第5頁
已閱讀5頁,還剩23頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

-.z.《Java程序設(shè)計實訓(xùn)》學(xué)生成績管理系統(tǒng)設(shè)計數(shù)據(jù)庫:CREATEDATABASE學(xué)生成績管理系統(tǒng)(1)教師信息表創(chuàng)建:createtable教師信息表(教師IDvarchar(8)primarykey,教師varchar(8)notnullunique,登錄密碼varchar(8)notnull,)(2)學(xué)籍信息表創(chuàng)建:createtable學(xué)籍信息表(**varchar(15)primarykey,varchar(8)notnull,年齡varchar(10),出生日期varchar(10),性別varchar(4),班級varchar(8)notnull,專業(yè)varchar(5),民族varchar(10),登錄密碼varchar(6)notnull)(3)成績信息表創(chuàng)建:createtable成績信息表(**varchar(15),計算機(jī)網(wǎng)絡(luò)varchar(8),計算機(jī)專業(yè)英語smallint,計算機(jī)信息技術(shù)基礎(chǔ)smallint,Java程序設(shè)計smallint,數(shù)據(jù)庫應(yīng)用實訓(xùn)教程smallint,高等數(shù)學(xué)smallint,*mlsmallint,)概要結(jié)構(gòu)分析:學(xué)生成績管理系統(tǒng)登錄界面學(xué)生成績管理系統(tǒng)登錄界面添加學(xué)生信息查看學(xué)生成績查看學(xué)生信息查看學(xué)生成績查看學(xué)生信息刪除學(xué)生信息修改學(xué)生信息添加學(xué)生成績添加學(xué)生信息學(xué)生登錄教師登錄添加學(xué)生信息查看學(xué)生成績查看學(xué)生信息查看學(xué)生成績查看學(xué)生信息刪除學(xué)生信息修改學(xué)生信息添加學(xué)生成績添加學(xué)生信息學(xué)生登錄教師登錄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:學(xué)生成績管理系統(tǒng)","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:學(xué)生成績管理系統(tǒng)","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("添加學(xué)生信息"); JMenuItemmName=newJMenuItem("學(xué)生成績查詢"); JMenuItemmScore=newJMenuItem("按成績查詢"); JMenuItemmNam1=newJMenuItem("查詢學(xué)生信息"); 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("系統(tǒng)");mOperate=newJMenu("數(shù)據(jù)操作");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("查詢學(xué)生信息");mScore=newJMenuItem("查詢學(xué)生成績");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,"學(xué)生成績管理系統(tǒng)\n\n電信學(xué)院\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("學(xué)生"); utton1=newutton("登錄"); utton2=newutton("取消");publicCJ(){super("學(xué)生生成績管理系統(tǒng)"); 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學(xué)籍信息表"; mainFramemf=newmainFrame(); mf.setLayout(null); mf.setVisible(true); mf.setLocation(300,300); mf.setResizable(false); mf.setTitle("學(xué)生成績管理系統(tǒng):教師登錄界面"); mf.setDefaultCloseOperation(JFrame.E*IT_ON_CLOSE); mf.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){ System.e*it(0); } }); JOptionPane.showMessageDialog(null,rs.getString("教師")+"老師!您好!歡迎登錄學(xué)生成績管理系統(tǒng)!");} }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學(xué)籍信息表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學(xué)籍信息表"; 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("學(xué)生")+"同學(xué)!您好!歡迎登錄學(xué)生成績管理系統(tǒng)!");}}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.添加學(xué)生基本信息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("專業(yè):",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();//創(chuàng)建面板對象Connectioncon;Statementsql;ResultSetrs;addForm(){ super("添加學(xué)生信息");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,"請輸入專業(yè)","溫馨提示",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:學(xué)生成績管理系統(tǒng)","ww","123"); Statementstmt=con.createStatement();inta=stmt.e*ecuteUpdate("insertinto學(xué)籍信息表(**,登錄密碼,,年齡,出生日期,性別,班級,專業(yè),民族)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.添加學(xué)生成績importjava.awt.*;importjava*.swing.*;importjava.awt.event.*;importjava.sql.*;publicclassaddScoree*tendsJFrameimplementsActionListener{staticaddScoress; JLabel[]label={newJLabel("**:"),newJLabel("計算機(jī)網(wǎng)絡(luò):"),newJLabel("Linu*操作系統(tǒng):"),newJLabel("計算機(jī)專業(yè)英語:"),newJLabel("計算機(jī)信息技術(shù)基礎(chǔ):"),newJLabel("Java程序設(shè)計:"),newJLabel("數(shù)據(jù)庫應(yīng)用實訓(xùn)教程:"),newJLabel("高等數(shù)學(xué):"),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("添加學(xué)生成績",JLabel.CENTER); Fontf=newFont("黑體",Font.BOLD,16);ints=100;publicaddScore() {super("添加學(xué)生信息");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:學(xué)生成績管理系統(tǒng)","ww","123"); Statementstmt=con.createStatement();inta=stmt.e*ecuteUpdate("insertinto成績信息表(**,計算機(jī)網(wǎng)絡(luò),Linu*操作系統(tǒng),計算機(jī)專業(yè)英語,計算機(jī)信息技術(shù)基礎(chǔ),Java程序設(shè)計,數(shù)據(jù)庫應(yīng)用實訓(xùn)教程,高等數(shù)學(xué),*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.修改學(xué)生信息:importjava*.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;publicclassmodifyForme*tendsJFrameimplementsActionListener{ JPaneljpl=newJPanel(); JLabelSCH=newJLabel("修改學(xué)生信息",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("專業(yè):",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:學(xué)生成績管理系統(tǒng)","ww","123");sql=con.createStatement();rs=sql.e*ecuteQuery("select*from學(xué)籍信息表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("專業(yè)"));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:學(xué)生成績管理系統(tǒng)","ww","123");sql=con.createStatement();re=sql.e*ecuteUpdate("Update學(xué)籍信息表set='"+nam.getTe*t()+"',年齡='"+tyear.getTe*t()+"',出生日期='"+tDate.getTe*t()+"',班級='"+clas.getTe*t()+"',專業(yè)='"+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.刪除學(xué)生信息importjava*.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;publicclassdeleteForme*tendsJFrameimplementsActionListener{JPaneljpl=newJPanel(); JLabelSCH=newJLabel("刪除學(xué)生信息",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("專業(yè):",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:學(xué)生成績管理系統(tǒng)","ww","123");sql=con.createStatement();rs=sql.e*ecuteQuery("select*from學(xué)籍信息表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("專業(yè)"));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) //實現(xiàn)刪除功能{try{con=DriverManager.getConnection("jdbc:odbc:學(xué)生成績管理系統(tǒng)","ww","123");sql=con.createStatement();re=sql.e*ecuteUpdate("DELETEFROM學(xué)籍信息表where**=

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論