java学生信息管理系统(84页).doc
-设计数据库:CREATE DATABASE 学生成绩管理系统(1)教师信息表创建:create table 教师信息表(教师ID varchar(8) primary key ,教师姓名 varchar(8) not null unique,登录密码 varchar(8) not null,)(2)学籍信息表创建:create table 学籍信息表(学号 varchar(15) primary key,姓名 varchar(8) not null ,年龄 varchar(10),出生日期 varchar(10),性别 varchar(4) ,班级 varchar(8) not null ,专业 varchar(5) ,民族 varchar(10),登录密码 varchar(6) not null)(3)成绩信息表创建:create table 成绩信息表(学号 varchar(15),计算机网络 varchar(8),计算机专业英语 smallint,计算机信息技术基础 smallint,Java程序设计 smallint ,数据库应用实训教程 smallint ,高等数学 smallint ,Xml smallint ,)概要结构分析:学生成绩管理系统登录界面添加学生信息查看学生成绩查看学生信息查看学生成绩查看学生信息删除学生信息修改学生信息添加学生成绩添加学生信息学生登录教师登录1.登录界面和主界面import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.awt.*;import java.awt.event.*;import java.sql.*;class myConnectionResultSet re;public myConnection()public ResultSet getResult(String sql)tryClass.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection conn=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123");Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);ResultSet re=stmt.executeQuery(sql);return re;catch(Exception e)System.out.println("getResult-"+e.toString();return null;public boolean executeSql(String sql)tryClass.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection conn=DriverManager.getConnection("jdbc:odbc:学生成绩管理系统","ww","123");Statement stmt=conn.createStatement();stmt.executeUpdate(sql);mit();return true;catch(Exception e)System.out.println("executeSql-"+e.toString();return false; class stuMainFrame extends JFrame implements ActionListenerJMenuBar jmb = new JMenuBar();JMenu Message = new JMenu("信息");JMenu Score = new JMenu("查询");JMenuItem Item1 = new JMenuItem("添加学生信息");JMenuItem mName=new JMenuItem("学生成绩查询");JMenuItem mScore=new JMenuItem("按成绩查询");JMenuItem mNam1=new JMenuItem("查询学生信息");JLabel label = new JLabel();public stuMainFrame()ImageIcon icon = new ImageIcon("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); public void actionPerformed(ActionEvent e)if(e.getSource()=Item1) new addForm().setVisible(true);else if(e.getSource()=mName) dispose();new Score1().setVisible(true);else if(e.getSource()=mScore)new scoreQueryForm().setVisible(true);else if(e.getSource()=mNam1)dispose(); new Serch1().setVisible(true); class mainFrame extends JFrame implements ActionListener JLabel label = new JLabel(); JMenuBar mBar= new JMenuBar(); JPanel p=new JPanel(); private JMenu mSystem,mOperate,mQuery,mHelp,myMenuUser; private JMenuItem mFile,mNew,mOpen,mExit,mAdd,mDel,mModify,mName,miShow,mScore,mAbout,miUser,mAddSc; public mainFrame() this.setJMenuBar(mBar); ImageIcon icon = new ImageIcon("src/images/1.jpg"); label.setIcon(icon); label.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight(); add(label); setSize(label.getWidth(),label.getHeight(); myMenuUser=new JMenu("用户");miUser=new JMenuItem("编辑用户");myMenuUser.add(miUser); mSystem=new JMenu("系统"); mOperate=new JMenu("数据操作"); mQuery=new JMenu("查询"); mHelp=new JMenu("帮助"); mBar.add(mSystem); mBar.add(mOperate); mBar.add(mQuery); mBar.add(mHelp); mBar.add(myMenuUser); mFile=new JMenuItem("文件"); mNew=new JMenuItem("新建"); mOpen=new JMenuItem("打开"); mExit=new JMenuItem("退出"); mSystem.add(mFile); mSystem.add(mNew); mSystem.add(mOpen); mSystem.addSeparator(); mSystem.add(mExit); mAdd=new JMenuItem("添加基本信息"); mAddSc=new JMenuItem("添加成绩信息"); mDel=new JMenuItem("删除"); mModify=new JMenuItem("修改"); mOperate.add(mAdd); mOperate.add(mAddSc); mOperate.add(mDel); mOperate.add(mModify); mName=new JMenuItem("查询学生信息"); mScore=new JMenuItem("查询学生成绩"); miShow=new JMenuItem("全部显示"); mQuery.add(mName); mQuery.add(mScore); mQuery.addSeparator(); mQuery.add(miShow); mAbout=new JMenuItem("软件信息"); 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); public void actionPerformed(ActionEvent e) if(e.getSource()=mExit) dispose(); new CJ().setVisible(true); else if(e.getSource()=mAbout) JOptionPane.showMessageDialog(this,"学生成绩管理系统nn电信学院nn2012年3月","软件信息",JOptionPane.INFORMATION_MESSAGE); else if(e.getSource()=mAdd) dispose(); new addForm().setVisible(true); else if(e.getSource()=mAddSc) dispose(); new addScore().setVisible(true); else if(e.getSource()=mDel) dispose(); new deleteForm().setVisible(true); else if(e.getSource()=mName) dispose(); new Serch().setVisible(true); else if(e.getSource()=mScore) dispose(); new Score().setVisible(true); else if(e.getSource()=mModify) new modifyForm().setVisible(true); else if(e.getSource()=miUser) new userFrame().setVisible(true); else if(e.getSource()=miShow) new freshTable().setVisible(true); class CJ extends JFrame implements ActionListenerJLabel t1=new JLabel("ID号:"); JLabel t3=new JLabel("密码:"); JLabel label = new JLabel(); public String zh=null; JTextField t2=new JTextField(null,15);JTextField t4=new JPasswordField(null,15);JRadioButton b=new JRadioButton("教师");JRadioButton b1=new JRadioButton("学生");JButton jB1=new JButton("登录");JButton jB2=new JButton("取消");public CJ ()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);ButtonGroup bg=new ButtonGroup(); 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); ImageIcon icon = new ImageIcon("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);public void actionPerformed(ActionEvent e) if (e.getSource()=jB2)System.exit(0);else if (e.getSource()=jB1)String username , password;username = t2.getText(); password = t4.getText();if(b.isSelected() if (username.toString().equals("")JOptionPane.showMessageDialog(null, "请输入用户名", "温馨提示", JOptionPane.INFORMATION_MESSAGE); else if (password.toString().equals("")JOptionPane.showMessageDialog(null, "请输入密码", "温馨提示", JOptionPane.INFORMATION_MESSAGE);elsemyConnection conn=new myConnection();ResultSet rs;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 学籍信息表" mainFrame mf=new mainFrame(); mf.setLayout(null); mf.setVisible(true); mf.setLocation(300,300); mf.setResizable(false); mf.setTitle("学生成绩管理系统:教师登录界面"); mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mf.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); JOptionPane.showMessageDialog( null ,rs.getString("教师姓名")+"老师!您好!欢迎登录学生成绩管理系统!" ) ; elseJOptionPane.showMessageDialog(null, "用户名或密码错误", "登录失败", JOptionPane.INFORMATION_MESSAGE); catch(Exception er)System.out.println(er.toString(); if(b1.isSelected() if (username.toString().equals("")JOptionPane.showMessageDialog(null, "请输入用户名", "温馨提示", JOptionPane.INFORMATION_MESSAGE); else if (password.toString().equals("")JOptionPane.showMessageDialog(null, "请输入密码", "温馨提示", JOptionPane.INFORMATION_MESSAGE);elsemyConnection conn=new myConnection();ResultSet rs;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 学籍信息表" stuMainFrame smf =new stuMainFrame(); smf.setSize(500,400); smf.setVisible(true); smf.setResizable(false); smf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); smf.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); JOptionPane.showMessageDialog( null ,rs.getString("学生姓名")+"同学!您好!欢迎登录学生成绩管理系统!" ) ; elseJOptionPane.showMessageDialog(null, "用户名或密码错误", "登录失败", JOptionPane.INFORMATION_MESSAGE); catch(Exception er)System.out.println(er.toString(); public static void main(String args) try UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName(); catch(Exception e) CJ frame=new CJ(); new mainFrame(); stuMainFrame stu = new stuMainFrame();2.添加学生基本信息import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.awt.*;import java.awt.event.*;import java.sql.*;public class addForm extends JFrame implements ActionListener JLabel label1 = new JLabel("添加基本信息",JLabel.CENTER);JLabel labxuehao=new JLabel("学号:",JLabel.CENTER);JLabel labyear=new JLabel("年龄:",JLabel.CENTER);JLabel labName=new JLabel("姓名:",JLabel.CENTER); JLabel labDate=new JLabel("出生日期:",JLabel.CENTER); JLabel labclass=new JLabel("班级:",JLabel.CENTER); JLabel labzy=new JLabel("专业:",JLabel.CENTER); JLabel labmz=new JLabel("民族:",JLabel.CENTER); JLabel labsex = new JLabel("性别:",JLabel.CENTER); JTextField txtName=new JTextField(20); JTextField txtDate=new JTextField(18); JTextField txtXueHao=new JTextField(20); JTextField txtYear=new JTextField(20); JTextField txtClass=new JTextField(20); JTextField txtZY=new JTextField(20); JTextField txtMZ=new JTextField(20); ButtonGroup bgp = new ButtonGroup();JRadioButton man = new JRadioButton("男");JRadioButton women = new JRadioButton("女"); JButton btnAdd=new JButton("添加"); JButton btnCancel=new JButton("返回"); JButton btnReset = new JButton("重置"); JPanel jpl=new JPanel(); /创建面板对象 Connection con; Statement sql; ResultSet rs; 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); public void actionPerformed(ActionEvent e) if(e.getSource()=btnCancel) dispose(); new mainFrame().setVisible(true);if(e.getSource()=btnAdd)if (txtXueHao.getText().toString().equals("")JOptionPane.showMessageDialog(null, "请输入学号", "温馨提示", JOptionPane.INFORMATION_MESSAGE);else if (txtName.getText()