java學(xué)生成績管理系統(tǒng)源碼.doc
《java學(xué)生成績管理系統(tǒng)源碼.doc》由會員分享,可在線閱讀,更多相關(guān)《java學(xué)生成績管理系統(tǒng)源碼.doc(23頁珍藏版)》請在裝配圖網(wǎng)上搜索。
文件addmessage.java代碼: import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; class addmessage extends JFrame implements ActionListener{ JTextField t1,t2,t3,t4,t5; JTable table; JButton but1; JLabel lab1,lab2,lab3,lab4,lab5; JPanel p1; addmessage(){ super("增加"); setBounds(350,100,470,400); setLayout(new GridLayout(1,1,10,10)); p1=new JPanel(); lab1=new JLabel("學(xué)號"); t1=new JTextField(10); lab2=new JLabel("姓名"); t2=new JTextField(10); lab3=new JLabel("課程名"); t3=new JTextField(10); lab4=new JLabel("狀態(tài)"); t4=new JTextField(10); lab5=new JLabel("成績"); t5=new JTextField(10); but1=new JButton("添加"); but1.addActionListener(this); p1.add(lab1); p1.add(t1); p1.add(lab2); p1.add(t2); p1.add(lab3); p1.add(t3); p1.add(lab4); p1.add(t4); p1.add(lab5); p1.add(t5); p1.add(but1); add(p1); setVisible(true); } public void actionPerformed(ActionEvent e){ int i=0 ; String sql1=null,sql2=null,update=null; String url="jdbc:mysql://localhost:3306/學(xué)生成績系統(tǒng)"; Connection con; Statement stmt; try{ Class.forName("org.gjt.mm.mysql.Driver"); }catch(java.lang.ClassNotFoundException e1){ System.err.println("ClassNotFoundException:"+e1.getMessage()); } if(e.getSource()==but1){ //添加------------------- try{ con=DriverManager.getConnection(url,"root","123"); stmt=con.createStatement(); sql1="INSERT INTO 學(xué)生成績表 VALUES ("+t1.getText()+","+t2.getText()+","+ t3.getText()+","+t4.getText()+","+t5.getText()+")"; String num1=t1.getText(); String num2=t1.getText(); String sele="select * from 學(xué)生成績表 where 學(xué)號="+num1+" and 課程名="+num2+""; ResultSet rs=stmt.executeQuery(sele); if(rs.next()){ JOptionPane.showMessageDialog(this, "已有該條記錄,請核實!"); } else{ stmt.executeUpdate(sql1); JOptionPane.showMessageDialog(this, "添加成功!"); } t1.setText(""); t2.setText(""); t3.setText(""); t4.setText(""); t5.setText(""); stmt.close(); con.close(); }catch(SQLException ex){ System.err.println("SQLException:"+ex.getMessage()); } } } } 文件deletemessage.java代碼 import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; class deletemessage extends JFrame implements ActionListener{ JTextField t1,t2,t3; JTable table; JButton but1; JLabel lab1,lab2,lab3; JPanel p1; deletemessage(){ super("刪除"); setBounds(350,100,470,400); setLayout(new GridLayout(1,1,10,10)); p1=new JPanel(); lab1=new JLabel("學(xué)號"); t1=new JTextField(10); lab2=new JLabel("姓名"); t2=new JTextField(10); lab3=new JLabel("課程名"); t3=new JTextField(10); but1=new JButton("刪除"); but1.addActionListener(this); p1.add(lab1); p1.add(t1); p1.add(lab2); p1.add(t2); p1.add(lab3); p1.add(t3); p1.add(but1); add(p1); setVisible(true); } public void actionPerformed(ActionEvent e){ String sql1=null,sql2=null; String url="jdbc:mysql://localhost:3306/學(xué)生成績系統(tǒng)"; Connection con; Statement stmt; try{ Class.forName("org.gjt.mm.mysql.Driver"); }catch(java.lang.ClassNotFoundException e1){ System.err.println("ClassNotFoundException:"+e1.getMessage()); } if(e.getSource()==but1){ //刪除---------------------------- try{ String num1=t1.getText(); String num2=t2.getText(); String num3=t3.getText(); sql2="delete from 學(xué)生成績表 where 學(xué)號="+num1+"and 課程名="+num3+""; con=DriverManager.getConnection(url,"root","123"); stmt=con.createStatement(); sql1="select * from 學(xué)生成績表 where 學(xué)號="+num1+" and 姓名="+num2+" and 課程名="+num3+""; ResultSet rs=stmt.executeQuery(sql1); if(rs.next()){ stmt.executeUpdate(sql2); JOptionPane.showMessageDialog(this, "刪除成功!"); } else{ JOptionPane.showMessageDialog(this, "沒有此條記錄!請重新輸入"); } t1.setText(""); stmt.close(); con.close(); }catch(SQLException ex){ System.err.println("SQLException:"+ex.getMessage()); } } }} 文件entry.java代碼 import java.awt.*; import java.awt.event.*; import java.sql.*; import javax.swing.*; class entry extends JFrame implements ActionListener{ int flag=1; String user,pass; JPanel pa; JLabel lab1,lab2; JTextField tf1; JPasswordField tf2; JButton btu1,btu2; JPanel pa1,pa2,pa4; entry(){ super("學(xué)生成績管理系統(tǒng)"); setBounds(400,200,400,300); GridBagLayout gbL=new GridBagLayout(); GridBagConstraints gbc=new GridBagConstraints(); setLayout(gbL); gbc.fill=GridBagConstraints.HORIZONTAL; gbc.anchor=GridBagConstraints.CENTER; lab1=new JLabel("請輸入帳號"); lab2=new JLabel("請輸入密碼"); tf2=new JPasswordField(10); tf2.setEchoChar(*); tf1=new JTextField(10); tf1.addActionListener(this); pa1=new JPanel(); pa1.add(lab1); pa1.add(tf1); gbc.gridx=1;gbc.gridy=1; gbc.insets=new Insets(2,5,0,5); gbL.setConstraints(pa1,gbc); add(pa1); tf2.addActionListener(this); pa2=new JPanel(); pa2.add(lab2); pa2.add(tf2); gbc.gridx=1;gbc.gridy=2; gbc.insets=new Insets(2,5,2,5); gbL.setConstraints(pa2,gbc); add(pa2); btu1=new JButton("確定"); btu1.addActionListener(this); btu2=new JButton("退出"); btu2.addActionListener(this); pa4=new JPanel(); pa4.add(btu1); pa4.add(btu2); gbc.gridx=1;gbc.gridy=4; gbc.insets=new Insets(2,5,2,5); gbL.setConstraints(pa4,gbc); add(pa4); } public void actionPerformed(ActionEvent e){ loginsure ls; if(e.getSource()==btu1){ user=tf1.getText(); pass=tf2.getText(); try{ ls=new loginsure(user,pass); this.setVisible(false); }catch (SQLException e1){ e1.printStackTrace(); }catch (ClassNotFoundException e1){ e1.printStackTrace(); } } if(e.getSource()==btu2){ dispose(); System.exit(0); } } } class loginsure{ int i=0; String name=null,pwd=null, ustype=null; public loginsure(String s,String a) throws SQLException,ClassNotFoundException{ String driver ="org.gjt.mm.mysql.Driver"; Class.forName(driver); String URL = "jdbc:mysql://localhost:3306/學(xué)生成績系統(tǒng)"; Connection conn = DriverManager.getConnection(URL,"root","123"); Statement stmt=conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from 用戶管理表"); while (rs.next()){ name=rs.getString("用戶名").trim(); pwd=rs.getString("密碼").trim(); ustype=rs.getString("權(quán)限組").trim(); if (s.equals(name)&&a.equals(pwd)){ i=1; if(ustype.trim().equals("管理員")){ teacher tea=new teacher(); tea.setVisible(true); } if(ustype.trim().equals("學(xué)生")){ student stu=new student(name); stu.setVisible(true); } } } if(i==0) JOptionPane.showMessageDialog(null, "用戶名或者密碼錯誤", "警告",JOptionPane.WARNING_MESSAGE); stmt.close(); conn.close(); } } 文件inquiry.java代碼 import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; class inquiry extends JFrame implements ActionListener{ JTextField t1; JTable table; JButton but1; JLabel lab1; JPanel p1; JTable table1=null; DefaultTableModel demod1=null; String n[]={"課程名","狀態(tài)","成績"}; String [][]data=new String[0][0]; String No; inquiry(String no){ super("成績"); No=no; setBounds(350,100,470,400); p1=new JPanel(); lab1=new JLabel("課程名"); t1=new JTextField(10); but1=new JButton("查詢成績"); but1.addActionListener(this); p1.add(lab1); p1.add(t1); p1.add(but1); demod1=new DefaultTableModel(data,n); table1=new JTable(demod1); JScrollPane s1=new JScrollPane(table1); p1.add(s1); add(p1); setVisible(true); } public void actionPerformed(ActionEvent e){ int i=0; String sql1; String url="jdbc:mysql://localhost:3306/學(xué)生成績系統(tǒng)"; Connection con; Statement stmt; try{ Class.forName("org.gjt.mm.mysql.Driver"); }catch(java.lang.ClassNotFoundException e1){ System.err.println("ClassNotFoundException:"+e1.getMessage()); } if(e.getSource()==but1){ try{ String num=t1.getText(); sql1="select * from 學(xué)生成績表 where 學(xué)號="+No+""; if(!num.equals("")){ sql1="select * from 學(xué)生成績表 where 課程名="+num+"and 學(xué)號="+No+""; } con=DriverManager.getConnection(url,"root","123"); stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(sql1); removeAllRecord(); while(rs.next()){ Vector data=new Vector(); data.addElement(rs.getString(3)); data.addElement(rs.getString(4)); data.addElement(rs.getString(5)); demod1.addRow(data); i=1; } if(i==0){ JOptionPane.showMessageDialog(this, "沒有此課程!請重新輸入"); } table1.revalidate(); t1.setText(""); stmt.close(); con.close(); } catch(SQLException ex){ System.err.println("SQLException:"+ex.getMessage()); }} } public void removeAllRecord(){//將界面上的所有記錄清空 int rowcount; while(true){//刪除所有存在的行 rowcount = demod1.getRowCount()-1; if(rowcount >= 0){ demod1.removeRow(rowcount); demod1.setRowCount(rowcount); } else break; } } } 文件main.java代碼 import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; public class main{ public static void main(String args[]){ entry ent=new entry(); ent.setVisible(true); ent.setResizable(false); } } 文件record.java代碼 import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; class record extends JFrame implements ActionListener{ JTextField t1; TextArea t; JButton but1; JLabel L1; JPanel p1; JTable table1=null; DefaultTableModel demod1=null; String n[]={"平均成績","優(yōu)秀","良好","不及格"}; String [][]data=new String[0][0]; public record(){ super("統(tǒng)計"); setBounds(350,30,470,610); setLayout(new GridLayout(1,1,10,10)); p1=new JPanel(); L1=new JLabel("課程名"); but1=new JButton("查詢"); but1.addActionListener(this); t1=new JTextField(10); p1.add(L1); p1.add(t1); p1.add(but1); demod1=new DefaultTableModel(data,n); table1=new JTable(demod1); JScrollPane s1=new JScrollPane(table1); p1.add(s1); add(p1); setVisible(true); } public void actionPerformed(ActionEvent e){ int i=0; String sql1; String sql2; String url="jdbc:mysql://localhost:3306/學(xué)生成績系統(tǒng)"; Connection con; Statement stmt; try{ Class.forName("org.gjt.mm.mysql.Driver"); }catch(java.lang.ClassNotFoundException e1){ System.err.println("ClassNotFoundException:"+e1.getMessage()); } if(e.getSource()==but1){ try{ String num1=t1.getText(); if(num1.equals("")){ JOptionPane.showMessageDialog(this, "學(xué)號不能為空","請輸入學(xué)號!",JOptionPane.WARNING_MESSAGE); } else{ sql1="select * from 學(xué)生成績表 where 學(xué)號="+num1+""; sql1="select avg(成績) from 學(xué)生成績表 where 課程名="+num1+""; sql2="select count(*) from 學(xué)生成績表 where 課程名="+num1+" and 成績>=90"; con=DriverManager.getConnection(url,"root","123"); stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(sql1); removeAllRecord(); while(rs.next()){ Vector data=new Vector(); data.addElement(rs.getInt(1)); /*data.addElement(rs.getString(3)); data.addElement(rs.getString(4)); data.addElement(rs.getString(5));*/ demod1.addRow(data); i=1; } rs=stmt.executeQuery(sql2); while(rs.next()) { int n = rs.getInt(1); System.out.println(n); } if(i==0){ JOptionPane.showMessageDialog(this, "沒有此條記錄!請重新輸入"); } table1.revalidate(); t1.setText(""); stmt.close(); con.close(); } }catch(SQLException ex){ System.err.println("SQLException:"+ex.getMessage()); } } } public void removeAllRecord(){//將界面上的所有記錄清空 int rowcount; while(true){//刪除所有存在的行 rowcount = demod1.getRowCount()-1; if(rowcount >= 0){ demod1.removeRow(rowcount); demod1.setRowCount(rowcount); } else break; } } } 文件revise.java代碼 import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; class revise extends JFrame implements ActionListener{ JTextField t1,t2,t3,t4,t5; JTable table; JButton but1; JLabel lab1,lab2,lab3,lab4,lab5; JPanel p1; int n=0; revise(){ super("修改"); setBounds(350,100,470,400); setLayout(new GridLayout(1,1,10,10)); p1=new JPanel(); lab1=new JLabel("學(xué)號"); t1=new JTextField(10); lab2=new JLabel("姓名"); t2=new JTextField(10); lab3=new JLabel("課程名"); t3=new JTextField(10); lab4=new JLabel("狀態(tài)"); t4=new JTextField(10); lab5=new JLabel("成績"); t5=new JTextField(10); but1=new JButton("修改"); but1.addActionListener(this); p1.add(lab1); p1.add(t1); p1.add(lab2); p1.add(t2); p1.add(lab3); p1.add(t3); p1.add(lab4); p1.add(t4); p1.add(lab5); p1.add(t5); p1.add(but1); add(p1); setVisible(true); } public void actionPerformed(ActionEvent e){ String sql1=null,update=null; String url="jdbc:mysql://localhost:3306/學(xué)生成績系統(tǒng)"; Connection con; Statement stmt; try{ Class.forName("org.gjt.mm.mysql.Driver"); }catch(java.lang.ClassNotFoundException e1){ System.err.println("ClassNotFoundException:"+e1.getMessage()); } if(e.getSource()==but1){ //修改--------------------------- try{ String num1=t3.getText(); String num2=t1.getText(); //String num3=t5.getText(); n= Integer.valueOf(t5.getText()).intValue(); System.out.print(n); con=DriverManager.getConnection(url,"root","123"); stmt=con.createStatement(); sql1="select * from 學(xué)生成績表 where 學(xué)號="+num2+" and 課程名="+num1+""; update="update 學(xué)生成績表 set 課程名="+t3.getText()+",狀態(tài)="+t4.getText()+",成績 ="+n+" where 學(xué)號="+num2+""; ResultSet rs=stmt.executeQuery(sql1); if(rs.next()){ stmt.executeUpdate(update); JOptionPane.showMessageDialog(this, "修改成功!"); } else{ JOptionPane.showMessageDialog(this, "沒有此條記錄!請重新輸入"); } t1.setText(""); t2.setText(""); t3.setText(""); t4.setText(""); t5.setText(""); stmt.close(); con.close(); } catch(SQLException ex){ System.err.println("SQLException:"+ex.getMessage()); } } }} 文件student.java代碼 import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; class student extends JFrame implements ActionListener{ inquiry cho; JMenuBar mb; JMenu m1; JMenuItem mt1,mt2; String No; Icon icon; JLabel lab; student(String no){ super("學(xué)生"); icon=new ImageIcon("123.jpg"); lab=new JLabel(icon); add(lab); No=no; setBounds(130,10,800,500); JMenuBar mb=new JMenuBar(); setJMenuBar(mb); m1=new JMenu("操作"); mt1=new JMenuItem("查詢成績"); mt2=new JMenuItem("退出"); m1.add(mt1); mt1.addActionListener(this); m1.addSeparator(); m1.add(mt2); mt2.addActionListener(this); m1.addActionListener(this); mb.add(m1); } public void actionPerformed(ActionEvent e){ if(e.getSource()==mt1) cho=new inquiry(No); if(e.getSource()==mt2) dispose(); } } 文件teacher.java代碼 import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; class teacher extends JFrame implements ActionListener{ addmessage add; deletemessage delete; revise re; user use; record rec; MenuBar mb; Menu m1; MenuItem mt1,mt2,mt3,mt4,mt5,mt6; Icon icon; JLabel lab; teacher(){ super("管理員"); setBounds(130,10,800,500); MenuBar mb=new MenuBar(); setMenuBar(mb); m1=new Menu("操作"); mt1=new MenuItem("增加"); mt2=new MenuItem("刪除"); mt3=new MenuItem("修改"); mt4=new MenuItem("查詢"); mt5=new MenuItem("統(tǒng)計"); mt6 = new MenuItem("退出"); icon=new ImageIcon("123.jpg"); lab=new JLabel(icon); add(lab); mt1.addActionListener(this); m1.add(mt1); mt2.addActionListener(this); m1.add(mt2); mt3.addActionListener(this); m1.add(mt3); mt4.addActionListener(this); m1.add(mt4); mt5.addActionListener(this); m1.add(mt5); m1.addSeparator(); mt6.addActionListener(this); m1.add(mt6); m1.addActionListener(this); mb.add(m1); } public void actionPerformed(ActionEvent e){ if(e.getSource()==mt1) add=new addmessage(); if(e.getSource()==mt2) delete=new deletemessage(); if(e.getSource()==mt3) re=new revise(); if(e.getSource()==mt4) use=new user(); if(e.getSource()==mt5) rec=new record(); if(e.getSource()==mt6) dispose(); } } 文件user.java代碼 import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; class user extends JFrame implements ActionListener{- 1.請仔細(xì)閱讀文檔,確保文檔完整性,對于不預(yù)覽、不比對內(nèi)容而直接下載帶來的問題本站不予受理。
- 2.下載的文檔,不會出現(xiàn)我們的網(wǎng)址水印。
- 3、該文檔所得收入(下載+內(nèi)容+預(yù)覽)歸上傳者、原創(chuàng)作者;如果您是本文檔原作者,請點此認(rèn)領(lǐng)!既往收益都?xì)w您。
下載文檔到電腦,查找使用更方便
0 積分
下載 |
- 配套講稿:
如PPT文件的首頁顯示word圖標(biāo),表示該PPT已包含配套word講稿。雙擊word圖標(biāo)可打開word文檔。
- 特殊限制:
部分文檔作品中含有的國旗、國徽等圖片,僅作為作品整體效果示例展示,禁止商用。設(shè)計者僅對作品中獨創(chuàng)性部分享有著作權(quán)。
- 關(guān) 鍵 詞:
- java 學(xué)生 成績管理系統(tǒng) 源碼
鏈接地址:http://m.italysoccerbets.com/p-6567402.html