当前位置:文档之家› JAVA学生信息管理系统实验报告

JAVA学生信息管理系统实验报告

JA V A程序设计实验报告学号:姓名:班级:实验、Java课程设计--------学生信息管理系统一、实验目的1.掌握Java基本语法2.理解面向对象编程特点3.理解Java I/O编程4.掌握Java图形界面编程5.掌握Java与不同数据库进行连接二、预习内容Java的基本语法知识、类和对象、Java Swing图形界面编程、Java I/O处理以及Java与数据库连接操作三、实验设备与环境通过局域网互联,安装Windows 2000/XP操作系统环境的JDK 1.6,my eclipse 或者EditPlus编程工具。

并安装MySQL数据库四、实验内容编写并调试运行Java程序,进行设计,掌握Java开发的基础。

五、实验任务设计学生信息管理系统。

要求包括1. 登陆模块:设立超级管理员权限,用户可以根据不同的权限登陆系统,超级管理员可以对学生信息进行增、删、改、查操作。

而普通用户只可以查找学生信息。

2. 包括学生添加信息模块、学生信息删除模块、学生信息修改模块和学生信息查询模块3.对于管理员,可以对管理员进行添加、删除以及修改密码等操作。

六、实验报告(要求独立完成参考程序的代码、编译、调试与运行)1、程序清单:1.1程序模块清单package Pan;import java.awt.event.ItemListener;import javax.swing.*;import ponent;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.event.InputEvent;import java.awt.event.ItemListener;import java.awt.event.KeyEvent;import java.awt.event.ActionListener; import java.awt.event.ActionEvent;import java.util.*;import java.awt.Color;import java.text.DecimalFormat;import java.sql.*;import java.sql.Date;import java.awt.*;import java.util.Vector;public class Res{/*** @param args*/public static void main(String[] args) {FirstWindow win =new FirstWindow("学生信息管理系统");}}class FirstWindow extends JFrame implements ActionListener{JMenuBar menubar;JMenu menu1,menu2,menu3,menu4;public final JMenuItem a11,a12,a13,a14,a15,a16,a17;public final JMenuItem a21,a22,a23,a24;public final JMenuItem a3;public final JMenuItem a4;public final JButton btn;JPanel pnl;JLabel label;boolean flag;FirstWindow(String s){setTitle(s);setSize(400,400);setLocation(100,100);setVisible(true);setDefaultCloseOperation(3);pnl=new JPanel();this.getContentPane().add(pnl);pnl.setLayout(new BorderLayout());label=new JLabel("欢迎使用学生管理系统",JLabel.CENTER);label.setForeground(Color.red);pnl.add(label,BorderLayout.CENTER);menubar=new JMenuBar();menu1=new JMenu("使用");menu2=new JMenu("用户管理");menu3=new JMenu("帮助");menu4=new JMenu("退出");a11=new JMenuItem("管理员登录");a12=new JMenuItem("查询学生信息");a13=new JMenuItem("更改学生信息");a14=new JMenuItem("删除学生信息");a15=new JMenuItem("添加学生信息");a16=new JMenuItem("超级管理员登录");a17=new JMenuItem("普通学生登录");a11.setEnabled(true);a16.setEnabled(true);a17.setEnabled(true);a12.setVisible(false);a13.setVisible(false);a14.setVisible(false);a15.setVisible(false);a21=new JMenuItem("添加用户");a22=new JMenuItem("删除用户");a23=new JMenuItem("更改用户");a24=new JMenuItem("修改密码");a21.setEnabled(false);a22.setEnabled(false);a23.setEnabled(false);a24.setEnabled(false);a3=new JMenuItem("系统介绍");a3.setEnabled(true);a4=new JMenuItem("退出");a4.setEnabled(true);btn=new JButton("再次确认登陆");pnl.add(btn,BorderLayout.EAST);btn.setSize(10,10); menu1.add(a11);menu1.addSeparator(); menu1.add(a16);menu1.addSeparator(); menu1.add(a17);menu1.addSeparator(); menu1.add(a12);menu1.addSeparator(); menu1.add(a13);menu1.addSeparator(); menu1.add(a14);menu1.addSeparator(); menu1.add(a15);menu1.addSeparator();menu2.add(a21);menu2.addSeparator(); menu2.add(a22);menu2.addSeparator(); menu2.add(a23);menu2.addSeparator();menu2.add(a24);menu2.addSeparator();menu3.add(a3);menu3.addSeparator();menu4.add(a4);menubar.add(menu1); menubar.add(menu2); menubar.add(menu3); menubar.add(menu4); setJMenuBar(menubar);a11.addActionListener(this); a12.addActionListener(this); a13.addActionListener(this); a14.addActionListener(this); a15.addActionListener(this); a16.addActionListener(this); a17.addActionListener(this); a21.addActionListener(this); a22.addActionListener(this); a23.addActionListener(this); a24.addActionListener(this); a3.addActionListener(this);a4.addActionListener(this);btn.addActionListener(this);}public void setColor(Color black) {// TODO Auto-generated method stub}public void actionPerformed(ActionEvent event) {Object temp=new Object();temp=event.getSource();if(temp==a11){Login login=new Login();login.Login();}if(temp==a12){ShowStu show=new ShowStu();show.ShowStu();}if(temp==a13){AlterStu alter=new AlterStu();alter.AlterStu();}if(temp==a14){DeleteStu delete=new DeleteStu();delete.DeleteStu();}if(temp==a15){AddStu add=new AddStu();add.AddStu();}if(temp==a16){superlog superlog=new superlog();superlog.superlog();}if(temp==a17){stuLogin stu=new stuLogin();stu.stuLogin();a12.setVisible(true);}if(temp==a21){AddUser add=new AddUser();add.AddUser();}if(temp==a22){DeleteUser delete=new DeleteUser();delete.DeleteUser();}if(temp==a23){AlterUser alter=new AlterUser();alter.AlterUser();}if(temp==a24){AlterPword pword=new AlterPword(); pword.AlterPword();}if(temp==a3){SystemHelp help=new SystemHelp();help.SystemHelp();}if(temp==a4){SystemExit exit1=new SystemExit();exit1.SystemExit();}if(temp==btn){Connection con;Statement st;Statement st1;ResultSet rs,rs1;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("" + e);}try{con=DriverManager.getConnection("jdbc:odbc:pan","","") ;st=con.createStatement();st1=con.createStatement();rs=st.executeQuery("SELECT * FROM Login");rs1=st1.executeQuery("SELECT * FROM superlog");if(rs.next()){a12.setVisible(true);a21.setEnabled(true);a22.setEnabled(true);a23.setEnabled(true);a24.setEnabled(true);Login login=new Login();login.Clear();}if(rs1.next()){a12.setVisible(true);a13.setVisible(true);a14.setVisible(true);a15.setVisible(true);superlog superlog=new superlog();lear();}con.close();}catch(SQLException e){System.out.println(e);}}}}主页面class Login{void Login(){final JFrame loginframe=new JFrame("登陆界面");loginframe.setBounds(200,200,400,500);loginframe.setVisible(true);loginframe.setResizable(true);loginframe.setLayout(null);final JTextField text1=new JTextField(10);final JPasswordField text2=new JPasswordField(10);JButton btn1=new JButton("登陆");JButton btn2=new JButton("取消");JLabel label1=new JLabel("用户名");JLabel label2=new JLabel("密码");loginframe.add(btn1);loginframe.add(btn2);loginframe.add(text1);loginframe.add(text2);loginframe.add(label1);loginframe.add(label2);label1.setBounds(80, 100, 50, 50);label2.setBounds(80, 200, 50, 50);btn1.setForeground(Color.black);btn2.setForeground(Color.black);text1.setBounds(150, 100, 200, 30);text2.setBounds(150, 200, 200, 30);btn1.setBounds(100, 300, 100, 60);btn2.setBounds(200, 300, 100, 60);btn1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){String name=text1.getText();String password=text2.getText();try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("" + e);}try{Connection con;Statement sql,st;ResultSet rs;con=DriverManager.getConnection("jdbc:odbc:pan","","") ;sql=con.createStatement();st=con.createStatement();rs=sql.executeQuery("SELECT username,password FROM users where username='"+name+"'");if(!rs.next()){JOptionPane b=new JOptionPane();b.showMessageDialog(null,"账号有误" ,"消息对话框",RMATION_MESSAGE);}else{String username=rs.getString(1);String pass=rs.getString(2);if( Integer.parseInt(password)==Integer.parseInt(pass) ){st.executeUpdate("INSERT INTO Login VALUES('"+username+"','"+pass+"')");loginframe.dispose();JOptionPane b=new JOptionPane();b.showMessageDialog(null,"登录成功" ,"消息对话框",RMATION_MESSAGE);}else{text1.setText("");text2.setText("");JOptionPanea=new JOptionPane();a.showMessageDialog(null,"您的账户名或者密码有误","消息对话框" ,RMATION_MESSAGE);}}}catch(SQLException e){System.out.println(e);}}});btn2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){loginframe.dispose();}});}void Clear(){Connection con;Statement st;ResultSet rs;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("" + e);}try{con=DriverManager.getConnection("jdbc:odbc:pan","","") ;st=con.createStatement();st.executeUpdate("DELETE FROM Login");con.close();}catch(SQLException e){System.out.println(e);}}}管理员登陆与权限class superlog{superlog(){final JFrame loginframe=new JFrame("登陆界面");loginframe.setBounds(200,200,400,500);loginframe.setVisible(true);loginframe.setResizable(true);loginframe.setLayout(null);final JTextField text1=new JTextField(10);final JPasswordField text2=new JPasswordField(10);JButton btn1=new JButton("登陆");JButton btn2=new JButton("取消");JLabel label1=new JLabel("超级用户名",JLabel.CENTER);JLabel label2=new JLabel("密码",JLabel.CENTER);loginframe.add(btn1);loginframe.add(btn2);loginframe.add(text1);loginframe.add(text2);loginframe.add(label1);loginframe.add(label2);label1.setBounds(80, 100, 100, 50);label2.setBounds(80, 200, 100, 50);btn1.setForeground(Color.black);btn2.setForeground(Color.black);text1.setBounds(150, 100, 200, 30);text2.setBounds(150, 200, 200, 30);btn1.setBounds(100, 300, 100, 60);btn2.setBounds(200, 300, 100, 60);btn1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){String name=text1.getText();@SuppressWarnings("deprecation")String password=text2.getText();tryClass.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("" + e);}try{Connection con;Statement sql;ResultSet rs;con=DriverManager.getConnection("jdbc:odbc:pan","","") ;sql=con.createStatement();rs=sql.executeQuery("SELECT Cusername,Cpassword FROM super where Cusername='"+name+"'");if(!rs.next())JOptionPane b=new JOptionPane();b.showMessageDialog(null,"超级账号错误" ,"消息对话框",RMATION_MESSAGE);}else{String username=null;String pass=null;username=rs.getString(1);pass=rs.getString(2);if( Integer.parseInt(password)==Integer.parseInt(pass) ){sql.executeUpdate("INSERT INTO superlog VALUES('"+username+"',"+"'"+pass+"')");JOptionPane b=new JOptionPane();b.showMessageDialog(null,"登录成功" ,"消息对话框",RMATION_MESSAGE);loginframe.dispose();}else{text1.setText("");text2.setText("");JOptionPane a=new JOptionPane();a.showMessageDialog(null,"您的账户名或者密码有误","消息对话框" ,RMATION_MESSAGE);}}}catch(SQLException e){System.out.println(e);}}});btn2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){loginframe.dispose();}});}public void superlog() {// TODO Auto-generated method stub }void Cclear(){Connection con;Statement st;ResultSet rs;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("" + e);}try{con=DriverManager.getConnection("jdbc:odbc:pan","","") ;st=con.createStatement();st.executeUpdate("DELETE FROM superlog");con.close();}catch(SQLException e){System.out.println(e);}}}超级管理员登陆界面与权限class stuLogin{void stuLogin(){final JFrame loginframe=new JFrame("登陆界面");loginframe.setBounds(200,200,400,500);loginframe.setVisible(true);loginframe.setResizable(true);loginframe.setLayout(null);final JTextField text1=new JTextField(15);final JPasswordField text2=new JPasswordField(15);JButton btn1=new JButton("登陆");JButton btn2=new JButton("取消");JLabel label1=new JLabel(" 学生姓名",JLabel.CENTER);JLabel label2=new JLabel("密码",JLabel.CENTER);loginframe.add(btn1);loginframe.add(btn2);loginframe.add(text1);loginframe.add(text2);loginframe.add(label1);loginframe.add(label2);label1.setBounds(80, 100, 100, 50);label2.setBounds(80, 200, 100, 50);btn1.setForeground(Color.black);btn2.setForeground(Color.black);text1.setBounds(150, 100, 200, 30);text2.setBounds(150, 200, 200, 30);btn1.setBounds(100, 300, 100, 60);btn2.setBounds(200, 300, 100, 60);btn1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){String name=text1.getText();String password=text2.getText();try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("" + e);}try{Connection con;Statement sql;ResultSet rs;con=DriverManager.getConnection("jdbc:odbc:pan","","") ;sql=con.createStatement();rs=sql.executeQuery("SELECTsname,sphone FROM student where sname='"+name+"' AND sphone='"+password+"'");if(rs.next()){JOptionPane a=new JOptionPane();a.showMessageDialog(null,"登陆成功","消息对话框" ,RMATION_MESSAGE);loginframe.dispose();}else{text1.setText("");text2.setText("");JOptionPane a=new JOptionPane();a.showMessageDialog(null,"您的账户名或密码有误","消息对话框" ,RMATION_MESSAGE);}con.close();}catch(SQLException e){System.out.println(e);}}});btn2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){loginframe.dispose();}});}}普通学生登陆与权限class ShowStu{void ShowStu(){JFrame frame1=new JFrame("学生信息窗口");frame1.setBounds(300,300,500,400);frame1.setDefaultCloseOperation(2);JTable table;Object a[][]=null;Object name[]={"学号","姓名","年龄","性别","籍贯","电话"};Connection con;Statement st;ResultSet rs;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("" + e);}try{con=DriverManager.getConnection("jdbc:odbc:pan",""," ");st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITI VE,ResultSet.CONCUR_READ_ONLY);rs=st.executeQuery("SELECT * FROM student");st();int lastnumber=rs.getRow();a=new Object[lastnumber][6];int i=0;rs.beforeFirst();while(rs.next()){a[i][0]=rs.getString(1);a[i][1]=rs.getString(2);a[i][2]=rs.getString(3);a[i][3]=rs.getString(4);a[i][4]=rs.getString(5);a[i][5]=rs.getString(6);i++;}con.close();}catch(SQLException e){System.out.println(e);}table=new JTable(a,name);frame1.setLayout(new BorderLayout());frame1.add(newJScrollPane(table),BorderLayout.CENTER);frame1.setVisible(true);frame1.validate();}}class AlterStu{void AlterStu(){JFrame deleteframe=new JFrame("更改学生信息");deleteframe.setLayout(null);JLabel label=new JLabel("需要修改的学生学号",JLabel.CENTER);deleteframe.setVisible(true);deleteframe.setBounds(350,350,450,350);JButton btn=new JButton("确定");deleteframe.add(label);label.setForeground(Color.red);final JTextField text=new JTextField(10);text.setSize(100,60);deleteframe.add(text);deleteframe.add(btn);label.setBounds(150, 50, 150, 20);text.setBounds(150, 100, 100, 20);btn.setBounds(150, 150, 100, 20);btn.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){String sno=text.getText();Connection con;Statement st;ResultSet rs;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println(e);}try{con=DriverManager.getConnection("jdbc:odbc:pan","","") ;st=con.createStatement();rs=st.executeQuery("SELECT * FROM student WHERE sno=+'"+sno+"'");if(rs==null){JOptionPane b=new JOptionPane();b.showMessageDialog(null,"该学生不存在" ,"消息对话框",RMATION_MESSAGE);}else{rs.next();final String no1=rs.getString(1);final String name1=rs.getString(2);final String age1=rs.getString(3);final String sex1=rs.getString(4);final String address1=rs.getString(5);final String phone1=rs.getString(6);JFrame addframe=new JFrame("修改学生信息");addframe.setDefaultCloseOperation(2);addframe.setBounds(400,200,450,600);addframe.setVisible(true);addframe.setResizable(true);addframe.validate();addframe.setLayout(newBorderLayout());Box basebox,box1,box2,box3,box4;basebox=Box.createHorizontalBox();box1=Box.createVerticalBox();box2=Box.createVerticalBox();box3=Box.createVerticalBox();box4=Box.createVerticalBox();JLabel no=new JLabel("学号");JLabel name=new JLabel("姓名");JLabel age=new JLabel("年龄");box1.add(Box.createVerticalStrut(90));box1.add(no);box1.add(Box.createVerticalStrut(90));box1.add(name);box1.add(Box.createVerticalStrut(90));box1.add(age);JLabel sex=new JLabel("性别");JLabel address =new JLabel("籍贯");JLabel phone=new JLabel("电话");box3.add(Box.createVerticalStrut(90));box3.add(sex);box3.add(Box.createVerticalStrut(90));box3.add(address);box3.add(Box.createVerticalStrut(90));box3.add(phone);final JTextField notext=new JTextField(15);final JTextField nametext=new JTextField(15);final JTextField agetext=new JTextField(15);final JTextField sextext=new JTextField(15);final JTextField addresstext=new JTextField(15);final JTextField phonetext=new JTextField(15);box2.add(Box.createVerticalStrut(90));box2.add(notext);box2.add(Box.createVerticalStrut(90));box2.add(nametext);box2.add(Box.createVerticalStrut(90));box2.add(agetext);box4.add(Box.createVerticalStrut(90));box4.add(sextext);box4.add(Box.createVerticalStrut(90));box4.add(addresstext);box4.add(Box.createVerticalStrut(90));box4.add(phonetext);basebox.add(box1);basebox.add(box2);basebox.add(box3);basebox.add(box4);。

相关主题