java学生成绩管理系统源码.doc

上传人:w****2 文档编号:6567402 上传时间:2020-02-29 格式:DOC 页数:23 大小:69KB
返回 下载 相关 举报
java学生成绩管理系统源码.doc_第1页
第1页 / 共23页
java学生成绩管理系统源码.doc_第2页
第2页 / 共23页
java学生成绩管理系统源码.doc_第3页
第3页 / 共23页
点击查看更多>>
资源描述
文件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(学号); t1=new JTextField(10); lab2=new JLabel(姓名); t2=new JTextField(10); lab3=new JLabel(课程名); t3=new JTextField(10); lab4=new JLabel(状态); 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/学生成绩系统; 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 学生成绩表 VALUES (+t1.getText()+,+t2.getText()+,+t3.getText()+,+t4.getText()+,+t5.getText()+); String num1=t1.getText(); String num2=t1.getText(); String sele=select * from 学生成绩表 where 学号=+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(学号); 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/学生成绩系统; 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 学生成绩表 where 学号=+num1+and 课程名=+num3+; con=DriverManager.getConnection(url,root,123); stmt=con.createStatement(); sql1=select * from 学生成绩表 where 学号=+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(学生成绩管理系统);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(); tryls=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,ClassNotFoundExceptionString driver =org.gjt.mm.mysql.Driver; Class.forName(driver); String URL = jdbc:mysql:/localhost:3306/学生成绩系统; 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(权限组).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(学生) 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=课程名,状态,成绩; String data=new String00; 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/学生成绩系统; 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 学生成绩表 where 学号=+No+; if(!num.equals() sql1=select * from 学生成绩表 where 课程名=+num+and 学号=+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=平均成绩,优秀,良好,不及格; String data=new String00; public record() super(统计); 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/学生成绩系统; 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, 学号不能为空,请输入学号!,JOptionPane.WARNING_MESSAGE); else sql1=select * from 学生成绩表 where 学号=+num1+; sql1=select avg(成绩) from 学生成绩表 where 课程名=+num1+; sql2=select count(*) from 学生成绩表 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(学号); t1=new JTextField(10); lab2=new JLabel(姓名); t2=new JTextField(10); lab3=new JLabel(课程名); t3=new JTextField(10); lab4=new JLabel(状态); 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/学生成绩系统; 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 学生成绩表 where 学号=+num2+ and 课程名=+num1+; update=update 学生成绩表 set 课程名=+t3.getText()+,状态=+t4.getText()+,成绩 =+n+ where 学号=+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(学生);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(统计); 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
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 临时分类 > 人文社科


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!