用java编写学生信息管理系统_第1页
用java编写学生信息管理系统_第2页
用java编写学生信息管理系统_第3页
用java编写学生信息管理系统_第4页
用java编写学生信息管理系统_第5页
免费预览已结束,剩余11页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精心整理用java编写学生信息管理系统import java.awt.*;import .*;import javax.swing.*;import java.io.*;import java.util.*;class Student implements String number,name,specialty,grade,borth,sex;public Student();勺”11丁public void setNumber(String number) this.number=number;public String getNumber() return number;public v

2、oid setName(String name) =name;public String getName() return name;public void setSex(String sex) this.sex=sex;public String getSex() return sex;public void setSpecialty(String specialty) this.specialty=specialty;public String getSpecialty() return specialty;public void setGrade(String grad

3、e) this.grade=grade;public String getGrade() return grade;public void setBorth(String borth) this.borth=borth;public String getBorth() return borth;精心整理精心整理 public class StudentManager extends JFrameJLabel lb=new JLabelC录入请先输入记录,查询、删除请先输入学号,修改是对查询”+“内容改后的保存!");static JTextField Jnumber,Jname,Js

4、pecialty,Jgrade,Jborth;static JRadioButton boy,girl;static ButtonGroup group=null;static JButton Login,select,delete,update,show;static JPanel p1,p2,p3,p4,p5,p6,pv,ph;static Student student=null;static Hashtable Shashtable=null;static File file=null;static FileInputStream inOne=null;static ObjectInp

5、utStream inTwo=null;static FileOutputStream outOne=null;static ObjectOutputStream outTwo=null;public StudentManager()super("学生基本信息管理系统");Jnumber=new JTextField(10);Jname =new JTextField(10);Jspecialty=new JTextField(10);Jgrade=new JTextField(10);精心整理精心整理Jborth=new JTextField(10);group=new

6、ButtonGroup();boy=new JRadioButton("男",true);girl=new JRadioButton("女"false);group.add(boy);group.add(girl);Login=new JButton("录入)select=new JButton('查询)delete=new JButton。删除)update=new JButton('修改)show=new JButton("显示)Login.addActionListener(new InputAct();sele

7、ct.addActionListener(new InquestAct();update.addActionListener(new ModifyAct();delete.addActionListener(new DeleteAct();show.addActionListener(new ShowAct();update.setEnabled(false);p1=new JPanel();p1.add(new JLabelC 学号:",JLabel.CENTER);p1.add(Jnumber);p2=new JPanel();p2.add(new JLabelC姓名:"

8、;,JLabel.CENTER);p2.add(Jname);精心整理p3=new JPanel();p3.add(new JLabel(性另 fj:",JLabel.CENTER);p3.add(boy);p3.add(girl);p4=new JPanel();p4.add(new JLabelC 专业:",JLabel.CENTER);p4.add(Jspecialty);p5=new JPanel();p5.add(new JLabelC 年级:",JLabel.CENTER);p5.add(Jgrade);p6=new JPanel();p6.add(n

9、ew JLabel("出生:",JLabel.CENTER);p6.add(Jborth);pv=new JPanel();pv.setLayout(new GridLayout(6,1);pv.add(pl);pv.add(p2);pv.add(p3);pv.add(p4);pv.add(p5);pv.add(p6);ph=new JPanel();ph.add(Login);精心整理精心整理ph.add(select);ph.add(update);ph.add(delete);ph.add(show);file=new File("学生信息.txt"

10、;);Shashtable=new Hashtable();if(!file.exists()tryFileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out);objectOut.writeObject(Shashtable);objectOut.close();out.close();catch(IOException e)Container con=getContentPane();con.setLayout(new BorderLayout

11、();con.add(lb, BorderLayout.NORTH);con.add(pv, BorderLayout.CENTER);con.add(ph, BorderLayout.SOUTH);setDefaultCloseOperation(EXIT_ON_CLOSE);setBounds(100,100,600,300);精心整理精心整理setVisible(true);public static void main(String口 args) new StudentManager();class InputAct implements ActionListenerpublic vo

12、id actionPerformed(ActionEvent e)update.setEnabled(false);String number=""number=Jnumber.getText();if(number.length()>0)tryinOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);Shashtable=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();catch(Exception ee)("创建

13、散列表出现问题!");if(Shashtable.containsKey(number)String warning="该生信息已存在,请到修改页面修改!JOptionPane.showMessageDialog(null,warning,警告”,JOptionPane.WARNING_MESSAGE);/end if1 elseString m="该生信息将被录入!"int ok=JOptionPane.showConfirmDialog(null,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPa

14、ne.INFORMATION_MESSAGE);if(ok=JOptionPane.YES_OPTION)String name=Jname.getText();String specialty=Jspecialty.getText();String grade=Jgrade.getText();String borth=Jborth.getText();String sex=null;if(boy.isSelected()sex=boy.getText();elsesex=girl.getText();student=new Student();student.setNumber(numbe

15、r);student.setName(name);student.setSpecialty(specialty);student.setGrade(grade);student.setBorth(borth);student.setSex(sex);tryoutOne=new FileOutputStream(file);outTwo=new ObjectOutputStream(outOne);Shashtable.put(number,student);outTwo.wHteObject(Shashtable);outTwo.close();outOne.close();catch(Exc

16、eption ee)("输出散列表出现问题!");Jnumber.setText(null);Jname.setText(null);Jspecialty.setText(null);Jgrade.setText(null);Jborth.setText(null);/end elsel/end if0elseString warning="必须输入学号!"JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);/end else。/en

17、d actionPerformed/end classclass InquestAct implements ActionListenerpublic void actionPerformed(ActionEvent e)String number=""number=Jnumber.getText();if(number.length()>0)tryinOne=new FilelnputStream(file);inTwo=new ObjectlnputStream(inOne);Shashtable=(Hashtable)inTwo.readObject();inO

18、ne.close();inTwo.close();catch(Exception ee)("散歹!J 表有问题! ");if(Shashtable.containsKey(number)update.setEnabled(true);Student stu=(Student)Shashtable.get(number);Jname.setText(stu.getName();Jspecialty.setText(stu.getSpecialty();Jgrade.setText(stu.getGrade();Jborth.setText(stu.getBorth();if(

19、stu.getSex().equalsC 男")boy.setSelected(true); elsegirl.setSelected(true);elsen.update.setEnabled(false);String warning="该学号不存在!JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);elseupdate.setEnabled(false);String warning="必须输入学号!"JOptionPane.

20、showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);class ModifyAct implements ActionListenerpublic void actionPerformed(ActionEvent e)String number=Jnumber.getText();String name=Jname.getText();String specialty=Jspecialty.getText();String grade=Jgrade.getText();String borth=J

21、borth.getText();String sex=null;if(boy.isSelected()sex=boy.getText();elsesex=girl.getText();Student 学生=new Student();学生.setNumber(number);学生.setName(name);学生.setSpecialty(specialty);学生.setGrade(grade);学生.setBorth(borth);学生.setSex(sex);tryoutOne=new FileOutputStream(file);outTwo=new ObjectOutputStrea

22、m(outOne);Shashtable.put(number,学生);outTwo.writeObject(Shashtable);outTwo.close();outOne.close();Jnumber.setText(null);Jname.setText(null);Jspecialty.setText(null);Jgrade.setText(null);Jborth.setText(null);catch(Exception ee)("录入修改出现异常!");update.setEnabled(false);精心整理精心整理class DeleteAct im

23、plements ActionListenerpublic void actionPerformed(ActionEvent e)update.setEnabled(false);String number=Jnumber.getText();if(number.length()>0)tryinOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);Shashtable=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();catch(Exception

24、 ee)if(Shashtable.containsKey(number)Student stu=(Student)Shashtable.get(number);Jname.setText(stu.getName();Jspecialty.setText(stu.getSpecialty();Jgrade.setText(stu.getGrade();Jborth.setText(stu.getBorth();if(stu.getSex().equalsC 男")boy.setSelected(true);elsegirl.setSelected(true);精心整理精心整理Stri

25、ng m="确定要删除该学生的记录吗?"int ok=JOptionPane.showConfirmDialog(null,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok=JOptionPane.YES_OPTION)Shashtable.remove(number);tryoutOne=new FileOutputStream(file);outTwo=new ObjectOutputStream(outOne);outTwo.writeObject(Shasht

26、able);outTwo.close();outOne.close();Jnumber.setText(null);Jname.setText(null);Jspecialty.setText(null);Jgrade.setText(null);Jborth.setText(null);catch(Exception ee)(ee);else if(ok=JOptionPane.NO_OPTION)Jnumber.setText(null);精心整理Jname.setText(null);Jspecialty.setText(null);Jgrade.setText(null);Jborth

27、.setText(null);elseString warning="该学号不存在!"JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);elseString warning="必须输入学号!"JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);class ShowAct implements ActionListenerpublic void actionPerformed(ActionEvent e)new StudentShow(file);精心整理精心整理class StudentShow extends JDialogHashtable学生散列表=null;JTextArea 显示=null;FileInputStream inOne=null;ObjectInputStream inTwo=null;File file=null;public StudentShow(File file)super(new JFram

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论