1、学生信息管理系统 一、 需求分析 1、可行性分析 知识爆炸时代里,求学人数越来越多,但学校数量及学校所能提供资源很有限。为优化管理学生人力资源,设计了这个系统。 2、任务概述 1)目标 在计算机网络,数据库和优异开发平台上,利用现有 软件、硬件资源,开发一个含有开放体系结构, 易扩充,易维护,含有良好人机交互界面学 生信息管理系统。 2)需求要求 这个简单学生信息管理系统包含以下两个基础功效: · 管理员登陆 · 学生信息管理 二、 层次图 学生信息管理系统 管理员登陆 学生信息管理 增加学生信息 查询学
2、生信息 修改学生信息 删除学生信息 显示学生信息 三、界面预览 登录界面 该管理员不存在 学生信息管理界面 填写学生信息 录入学生信息 按学号进行查询 查询后能够进行信息修改 学生信息删除 显示全部学生信息 四、系统说明 1该系统并未使用数据库,只是把信息存放在了一个新建立文本文档中 2相关管理员信息,必需现在C盘建立一个名为Login文本文档,在Login中存入用户名和密码且必需分行写入 3若要修改学生信息必需优异行信息查询,查询后方可进行信息修改 五、源代码 登录界面源代码
3、 import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.BufferedReader; import java.io.File; import java.io.FileReader;
4、 import java.io.IOException; import java.util.*; import java.sql.*; class Login extends JFrame implements ActionListener { Container cp=null; String name=null; String psw=null; JFrame f=null; JButton j1,j2; JTextField t1; JPasswordField t2; JLabel jlable1,jlable
5、2; Color c; JPanel jp1,jp2; Login(){ f=new JFrame("学生管理系统"); j1=new JButton("确定"); j2=new JButton("取消"); cp=f.getContentPane(); jlable1=new JLabel(" 输入用户名"); jlable2=new JLabel(" 用户密码"); jp1=new JPanel(); jp2=new JPanel(); t1=new JTextField(18)
6、 t2=new JPasswordField(18); jp1.add(jlable1); jp1.add(t1); jp1.add(jlable2); jp1.add(t2); JLabel JL=new JLabel("欢迎进入学生管理系统",SwingConstants.CENTER); cp.add(JL,"North"); jp2.add(j1); jp2.add(j2
7、); cp.add(jp1,"Center"); cp.add("South",jp2); jp1.setBackground(Color.lightGray); Toolkit kit=Toolkit.getDefaultToolkit(); Dimension screen=kit.getScreenSize(); int x=screen.width; /*取得显示器窗口宽度*/ int y=screen.height; /*取得显示器窗口高度*/ //setSize(x,y); /*让系统窗口平铺整
8、个显示器窗口*/ f.setSize(300,300); int xcenter=(x-300)/2; int ycenter=(y-300)/2; f.setLocation(xcenter,ycenter);/*显示在窗口中央*/ f.setVisible(true); //----------------------------------------------------- j1.addActionListener(this);//注册事件监听器 j2
9、addActionListener(this); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } public void confirm() throws IOException//验证用户和密码是否存在 { File file = new File("C://Login.txt"); try { if(!file.exists())
10、 file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } BufferedReader br = new BufferedReader(new FileReader(file)); String temp=br.readLine(); String line; while((line=br.readLine())!=null){ temp+=","+line; } if(temp==null){ System.out.println(
11、); }else{ ///分割字符串 String[] str=temp.split(","); name=str[0]; psw=str[1]; if(t1.getText().trim().equals(name)&&t2.getText().trim().equals(psw)){ new Test(); f.hide(); br.close(); }else{ JOptionPane.showMessageDialog(null,"该用户不存在","提醒!",
12、JOptionPane.YES_NO_OPTION); } t1.setText(""); t2.setText(""); //for(int i=0;i>str.length;i++){ //System.out.println(str[i]); //} } } public void actionPerformed(ActionEvent e) { String cmd=e.getActionCommand(); if(cmd.equals(
13、"确定")){ try { confirm(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if(cmd.equals("取消")){ f.dispose(); } } public static void main(String []arg){ Login a=new Login(); }
14、 } 学生信息管理界面源代码 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; class Student implements java.io.Serializable{ String number,name,specialty,grade,borth,sex; public Student(){}; public void setNumber(String number){ this.n
15、umber=number;} public String getNumber(){ return number;} public void setName(String name){ this.name=name;} public String getName(){ return name;} public void setSex(String sex){ this.sex=sex;} public String getSex(){ return sex;} public void setSpecialty(String specia
16、lty){ this.specialty=specialty;} public String getSpecialty(){ return specialty;} public void setGrade(String grade){ this.grade=grade;} public String getGrade(){ return grade;} public void setBorth(String borth){ this.borth=borth;} public String getBorth(){ return borth;}
17、} public class Test extends JFrame{ JLabel lb=new JLabel("录入请先输入统计,查询、删除请先输入学号,修改是对查询" + "内容改后保留!"); JTextField 学号,姓名,专业,年级,出生; JRadioButton 男,女; ButtonGroup group=null; JButton 录入,查询,删除,修改,显示; JPanel p1,p2,p3,p4,p5,p6,pv,ph; Student 学生=null; Has
18、htable 学生散列表=null; File file=null; FileInputStream inOne=null; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; public Test(){ super("学生信息管理系统"); 学号=new JTextField(10); 姓名=new JTextField(10); 专业=new
19、JTextField(10); 年级=new JTextField(10); 出生=new JTextField(10); group=new ButtonGroup(); 男=new JRadioButton("男",true); 女=new JRadioButton("女",false); group.add(男); group.add(女); 录入=new JButton("录入"); 查询=new JButton("查询"); 删除=new JBu
20、tton("删除"); 修改=new JButton("修改"); 显示=new JButton("显示"); 录入.addActionListener(new InputAct()); 查询.addActionListener(new InquestAct()); 修改.addActionListener(new ModifyAct()); 删除.addActionListener(new DeleteAct()); 显示.addActionListener(new ShowAct());
21、 修改.setEnabled(false); p1=new JPanel(); p1.add(new JLabel("学号:",JLabel.CENTER)); p1.add(学号); p2=new JPanel(); p2.add(new JLabel("姓名:",JLabel.CENTER)); p2.add(姓名); p3=new JPanel(); p3.add(new JLabel("性别:",JLabel.CENTER)); p3.add(男);
22、 p3.add(女); p4=new JPanel(); p4.add(new JLabel("专业:",JLabel.CENTER)); p4.add(专业); p5=new JPanel(); p5.add(new JLabel("年级:",JLabel.CENTER)); p5.add(年级); p6=new JPanel(); p6.add(new JLabel("出生:",JLabel.CENTER)); p6.add(出生); pv=
23、new JPanel(); pv.setLayout(new GridLayout(6,1)); pv.add(p1); pv.add(p2); pv.add(p3); pv.add(p4); pv.add(p5); pv.add(p6); ph=new JPanel(); ph.add(录入); ph.add(查询); ph.add(修改); ph.add(删除); ph.add(显示); file
24、new File("学生信息.txt"); 学生散列表=new Hashtable(); if(!file.exists()){ try{ FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(学生散列表);
25、 objectOut.close(); out.close(); } catch(IOException e){} } Container con=getContentPane(); con.setLayout(new BorderLayout()); con.add(lb, BorderLayout.NORTH); con.add(pv, BorderLayout.CENTER); con.a
26、dd(ph, BorderLayout.SOUTH); setDefaultCloseOperation(EXIT_ON_CLOSE); setBounds(100,100,600,300); setVisible(true); } public static void main(String[] args) {new Test();} class InputAct implements ActionListener{ public void actionPerformed(ActionE
27、vent e){ 修改.setEnabled(false); String number=""; number=学号.getText(); if(number.length()>0){ try{ inOne=new FileInputStream(file); inTwo=new ObjectInputStream(inOne); 学生散列表=(Hashtab
28、le)inTwo.readObject(); inOne.close(); inTwo.close(); } catch(Exception ee){System.out.println("创建散列表出现问题!");} if(学生散列表.containsKey(number)){ String warning="该生信息已存在,请到修改页面修改!"; JO
29、ptionPane.showMessageDialog(null,warning,"警告", JOptionPane.WARNING_MESSAGE); }//end if1 else{ String m="该生信息将被录入!"; int ok=JOptionPane.showConfirmDialog(null,m,"确定", JOptionPane.
30、YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE); if(ok==JOptionPane.YES_OPTION){ String name=姓名.getText(); String specialty=专业.getText(); String grade=年级.getText(); String borth=出生.getText()
31、 String sex=null; if(男.isSelected()){sex=男.getText();} else{sex=女.getText();} 学生=new Student(); 学生.setNumber(number); 学生.setName(name); 学生
32、setSpecialty(specialty); 学生.setGrade(grade); 学生.setBorth(borth); 学生.setSex(sex); try{ outOne=new FileOutputStream(file); outTwo=new ObjectOutputStream(ou
33、tOne); 学生散列表.put(number,学生); outTwo.writeObject(学生散列表); outTwo.close(); outOne.close(); } catch(Exception ee){System.out.println("输出散列表出现问题!");}
34、 学号.setText(null); 姓名.setText(null); 专业.setText(null); 年级.setText(null); 出生.setText(null); } }//end else1 }//end if0 else{
35、 String warning="必需输入学号!"; JOptionPane.showMessageDialog(null,warning, "警告",JOptionPane.WARNING_MESSAGE); }//end else0 }//end actionPerformed }//end class class InquestAct implements ActionListener{ public void actionPerf
36、ormed(ActionEvent e){ String number=""; number=学号.getText(); if(number.length()>0){ try{ inOne=new FileInputStream(file); inTwo=new ObjectInputStream(inOne); 学生散列表=(Hashtable)inTwo.readObject()
37、 inOne.close(); inTwo.close(); } catch(Exception ee){System.out.println("散列表有问题!");} if(学生散列表.containsKey(number)){ 修改.setEnabled(true); Student stu=(Student)学生散列表.get(number);
38、 姓名.setText(stu.getName()); 专业.setText(stu.getSpecialty()); 年级.setText(stu.getGrade()); 出生.setText(stu.getBorth()); if(stu.getSex().equals("男")){男.setSelected(true);} else{女.setSelected(true);}
39、 } else{ 修改.setEnabled(false); String warning="该学号不存在!"; JOptionPane.showMessageDialog(null,warning, "警告",JOptionPane.WARNING_MESSAGE); } } else{ 修改.setEnabl
40、ed(false); String warning="必需输入学号!"; JOptionPane.showMessageDialog(null,warning, "警告",JOptionPane.WARNING_MESSAGE); } } } class ModifyAct implements ActionListener{ public void actionPerformed(ActionEvent e){
41、 String number=学号.getText(); String name=姓名.getText(); String specialty=专业.getText(); String grade=年级.getText(); String borth=出生.getText(); String sex=null; if(男.isSelected()){sex=男.getText();} else{sex=女.get
42、Text();} Student 学生=new Student(); 学生.setNumber(number); 学生.setName(name); 学生.setSpecialty(specialty); 学生.setGrade(grade); 学生.setBorth(borth); 学生.setSex(sex); try{ outOne=new FileOutputStr
43、eam(file); outTwo=new ObjectOutputStream(outOne); 学生散列表.put(number, 学生); outTwo.writeObject(学生散列表); outTwo.close(); outOne.close(); 学号.setText(null); 姓名.setText(null); 专业.s
44、etText(null); 年级.setText(null); 出生.setText(null); } catch(Exception ee){ System.out.println("录入修改出现异常!"); 修改.setEnabled(false); } } } class DeleteAct implements ActionListener{
45、 public void actionPerformed(ActionEvent e){ 修改.setEnabled(false); String number=学号.getText(); if(number.length()>0){ try{ inOne=new FileInputStream(file); inTwo=new ObjectInputStream(inOne); 学
46、生散列表=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); } catch(Exception ee){} if(学生散列表.containsKey(number)){ Student stu=(Student)学生散列表.get(number); 姓名.setText(stu.getName
47、)); 专业.setText(stu.getSpecialty()); 年级.setText(stu.getGrade()); 出生.setText(stu.getBorth()); if(stu.getSex().equals("男")){男.setSelected(true);} else{女.setSelected(true);} } String m="确定
48、要删除该学生统计吗?"; int ok=JOptionPane.showConfirmDialog(null,m,"确定", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); if(ok==JOptionPane.YES_OPTION){ 学生散列表.remove(number); try{ outOne=new F
49、ileOutputStream(file); outTwo=new ObjectOutputStream(outOne); outTwo.writeObject(学生散列表); outTwo.close(); outOne.close(); 学号.setText(null); 姓名.setText(null);
50、 专业.setText(null); 年级.setText(null); 出生.setText(null); } catch(Exception ee){System.out.println(ee);} } else if(ok==JOptionPane.NO_OPTION){ 学号.setTe






