• 145.00 KB
  • 2022-05-26 19:18:01 发布

java课程设计-简单的班级管理系统

  • 17页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档共5页,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  4. 文档侵权举报电话:19940600175。
Java课程设计------简单的班级管理系统 二:总体设计本班级管理系统共有2个java源文件。各个类之间的主要关系如下图所示:StudentManagerModiifyActInquesActShowActDeleteActInputActStudentShowStudent各主类的主要作用如下:1.StudentManager.javaStudentManager类该类负责创建班级学生管理系统的主窗口。该类包含main方法,程序从该类开始执行。该类嵌套如下类:1).InputAct类该类负责创建班级学生管理系统的学生基本信息录入界面。2).InquestAct类该类负责创建班级学生管理系统的学生基本信息查询界面。3).ModifyAct类该类负责创建班级学生管理系统的学生基本信息修改界面。4).DeleteAct类该类负责创建班级学生管理系统的学生基本信息删除界面。5)..ShowAct类该类负责创建班级学生管理系统的学生基本信息显示界面。2.Student.java负责创建存放学生信息的对象。三:详细设计1.StudentManager.javaStudentManager类 1).成员变量主要成员变量成员变量描述变量类型变量名称显示注释的标签JLabellb显示欢迎进入的标签JLabel欢迎设定字体属性Fontfont1输入学生基本信息的文本JTextField学号,姓名,专业,年级,出生,电话,住址性别选择JRadioButton男,女进行相应操作的按钮JButton录入,查询,删除,修改,显示,进入,确定,退出调整布局的通道JPanelp01,p02,p03,p04,p1,p2,p3,p4,p5,p6,p7,p8,p9,pv,ph,plb系统框架界面JFrameWelcome,operation存放学生基本信息的对象Student学生学生信息的散列表Hashtable基本信息存放散列表的文件Filefile2).方法主要方法名称功能备注StudentManager创建程序主窗口构造方法Main程序开始运行3).内部类名称功能InputAct学生信息录入界面InquestAct学生信息查询界面ModifyAct学生信息修改界面DeleteAct学生信息删除界面ShowAct学生信息显示界面4).代码StudentManager.javaimportjava.awt.*;importjava.awt.event.*;importjavax.swing.*; importjava.io.*;importjava.util.*;publicclassStudentManagerextendsJFrame{JLabellb=newJLabel("注:录入请先输入记录,查询、删除请先输入学号,修改是对查询"+"内容改后的保存!");JLabel欢迎;Fontfont1=newFont("黑体",Font.BOLD,24);JTextField学号,姓名,专业,年级,出生,电话,住址;JRadioButton男,女;ButtonGroupgroup=null;JButton录入,查询,删除,修改,显示,进入,确定,退出;JPanelp01,p02,p03,p04,p1,p2,p3,p4,p5,p6,p7,p8,p9,pv,ph,plb;Student学生=null;Hashtable学生散列表=null;Filefile=null;FileInputStreaminOne=null;ObjectInputStreaminTwo=null;FileOutputStreamoutOne=null;ObjectOutputStreamoutTwo=null;publicStudentManager(){finalJFramewelcome=newJFrame();finalJFrameoperation=newJFrame();p01=newJPanel();……欢迎=newJLabel("欢迎进入班级管理系统!");欢迎.setFont(font1);进入=newJButton("进入");退出=newJButton("退出");welcome.setLayout(newGridLayout(3,1,5,5));p01.add(欢迎);p02.add(进入);welcome.add(p03);welcome.add(p01);welcome.add(p02); welcome.setTitle("班级管理系统");welcome.setSize(500,300);welcome.setVisible(true);进入.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){welcome.setVisible(false);operation.setVisible(true);}});退出.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){System.exit(0);}});operation.setTitle("班级管理系统");学号=newJTextField(10);……group=newButtonGroup();男=newJRadioButton("男",true);女=newJRadioButton("女",false);group.add(男);group.add(女);录入=newJButton("录入");……录入.addActionListener(newInputAct());……修改.setEnabled(false);确定.setVisible(false);确定.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){姓名.setEnabled(true);男.setEnabled(true);女.setEnabled(true);……确定.setVisible(false);}});p1=newJPanel();p1.add(newJLabel("学号:",JLabel.CENTER)); p1.add(学号);……p9=newJPanel();p9.add(确定);pv=newJPanel();pv.setLayout(newGridLayout(10,1));pv.add(p04);pv.add(p1);……pv.add(p9);ph=newJPanel();ph.add(录入);……ph.add(退出);plb=newJPanel();plb.add(lb);file=newFile("学生信息.txt");学生散列表=newHashtable();if(!file.exists()){try{FileOutputStreamout=newFileOutputStream(file);ObjectOutputStreamobjectOut=newObjectOutputStream(out);objectOut.writeObject(学生散列表);objectOut.close();out.close();}catch(IOExceptione){}}operation.setLayout(newBorderLayout());operation.add(ph,BorderLayout.NORTH);operation.add(pv,BorderLayout.CENTER);operation.add(plb,BorderLayout.SOUTH);operation.setDefaultCloseOperation(EXIT_ON_CLOSE);operation.setSize(700,500);operation.setVisible(false);}(1).录入界面InputAct类1).成员变量主要成员变量 描述变量类型变量名称获取输入的学号,姓名,专业,年级,出生,住址,电话Stringnumber,name,specialty,grade,borth,address,phonenumber,sex2).方法主要方法名称功能备注actionPerformed处理ActionEvent事件接口方法3).代码classInputActimplementsActionListener{publicvoidactionPerformed(ActionEvente){修改.setEnabled(false);Stringnumber="";number=学号.getText();if(number.length()>0){try{inOne=newFileInputStream(file);inTwo=newObjectInputStream(inOne);学生散列表=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exceptionee){System.out.println("创建散列表出现问题!");}if(学生散列表.containsKey(number)){Stringwarning="该生信息已存在,请到修改页面修改!";JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);}else{Stringm="该生信息将被录入!";intok=JOptionPane.showConfirmDialog(null,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);if(ok==JOptionPane.YES_OPTION){Stringname=姓名.getText();Stringspecialty=专业.getText(); Stringgrade=年级.getText();Stringborth=出生.getText();Stringaddress=住址.getText();Stringphonenumber=电话.getText();Stringsex=null;if(男.isSelected()){sex=男.getText();}else{sex=女.getText();}学生=newStudent();学生.setNumber(number);学生.setName(name);学生.setSpecialty(specialty);学生.setGrade(grade);学生.setBorth(borth);学生.setSex(sex);try{outOne=newFileOutputStream(file);outTwo=newObjectOutputStream(outOne);学生散列表.put(number,学生);outTwo.writeObject(学生散列表);outTwo.close();outOne.close();}catch(Exceptionee){System.out.println("输出散列表出现问题!");}学号.setText(null);姓名.setText(null);专业.setText(null);年级.setText(null);出生.setText(null);}}}else{Stringwarning="必须输入学号!";JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);}}} (2).查询界面InquestAct类1).成员变量主要成员变量描述变量属性变量名称获取输入的学号Stringnumber2).方法主要方法名称功能备注actionPerformed处理ActionEvent事件接口方法3).代码classInquestActimplementsActionListener{publicvoidactionPerformed(ActionEvente){Stringnumber="";number=学号.getText();if(number.length()>0){try{inOne=newFileInputStream(file);inTwo=newObjectInputStream(inOne);学生散列表=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exceptionee){System.out.println("散列表有问题!");}if(学生散列表.containsKey(number)){修改.setEnabled(true);Studentstu=(Student)学生散列表.get(number);姓名.setText(stu.getName());专业.setText(stu.getSpecialty());年级.setText(stu.getGrade());出生.setText(stu.getBorth());if(stu.getSex().equals("男")){男.setSelected(true);}else{女.setSelected(true);}}else{修改.setEnabled(false);Stringwarning="该学号不存在!"; JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);}}else{修改.setEnabled(false);Stringwarning="必须输入学号!";JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);}姓名.setEnabled(false);男.setEnabled(false);女.setEnabled(false);专业.setEnabled(false);年级.setEnabled(false);出生.setEnabled(false);电话.setEnabled(false);住址.setEnabled(false);确定.setVisible(true);录入.setEnabled(false);修改.setEnabled(false);删除.setEnabled(false);显示.setEnabled(false);}}(3).修改界面ModifyAct类1).成员变量主要成员变量描述变量类型变量名称获取修改的学号,姓名,Stringnumber,name,specialty,grade,borth,address,phonenumber,sex 专业,年级,出生,住址,电话2).方法主要方法名称功能备注actionPerformed处理ActionEvent事件接口方法3).代码classModifyActimplementsActionListener{publicvoidactionPerformed(ActionEvente){Stringnumber=学号.getText();Stringname=姓名.getText();Stringspecialty=专业.getText();Stringgrade=年级.getText();Stringborth=出生.getText();Stringphonenumber=电话.getText();Stringaddress=住址.getText();Stringsex=null;if(男.isSelected()){sex=男.getText();}else{sex=女.getText();}Stringm="确定要保存修改该学生的记录吗?";intok=JOptionPane.showConfirmDialog(null,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok==JOptionPane.YES_OPTION){Student学生=newStudent();学生.setNumber(number);学生.setName(name);学生.setSpecialty(specialty);学生.setGrade(grade);学生.setBorth(borth);学生.setSex(sex);学生.setAddress(address);学生.setPhonenumber(phonenumber);try{outOne=newFileOutputStream(file);outTwo=newObjectOutputStream(outOne);学生散列表.put(number,学生); outTwo.writeObject(学生散列表);outTwo.close();outOne.close();学号.setText(null);姓名.setText(null);专业.setText(null);年级.setText(null);出生.setText(null);电话.setText(null);住址.setText(null);}catch(Exceptionee){System.out.println("录入修改出现异常!");修改.setEnabled(false);}}}}(4).删除界面DeleteAct类1).成员变量主要成员变量描述变量属性变量名称获取输入的学号Stringnumber2).方法主要方法名称功能备注actionPerformed处理ActionEvent事件接口方法3).代码classDeleteActimplementsActionListener{publicvoidactionPerformed(ActionEvente){修改.setEnabled(false);Stringnumber=学号.getText();if(number.length()>0){try{inOne=newFileInputStream(file);inTwo=newObjectInputStream(inOne);学生散列表=(Hashtable)inTwo.readObject(); inOne.close();inTwo.close();}catch(Exceptionee){}if(学生散列表.containsKey(number)){Studentstu=(Student)学生散列表.get(number);姓名.setText(stu.getName());专业.setText(stu.getSpecialty());年级.setText(stu.getGrade());出生.setText(stu.getBorth());电话.setText(stu.getPhonenumber());住址.setText(stu.getAddress());if(stu.getSex().equals("男")){男.setSelected(true);}else{女.setSelected(true);}}Stringm="确定要删除该学生的记录吗?";intok=JOptionPane.showConfirmDialog(null,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok==JOptionPane.YES_OPTION){学生散列表.remove(number);try{outOne=newFileOutputStream(file);outTwo=newObjectOutputStream(outOne);outTwo.writeObject(学生散列表);outTwo.close();outOne.close();学号.setText(null);姓名.setText(null);专业.setText(null);年级.setText(null);出生.setText(null);电话.setText(null);住址.setText(null);}catch(Exceptionee){System.out.println(ee);}}elseif(ok==JOptionPane.NO_OPTION){学号.setText(null); 姓名.setText(null);专业.setText(null);年级.setText(null);出生.setText(null);电话.setText(null);住址.setText(null);}else{Stringwarning="该学号不存在!";JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);}}else{Stringwarning="必须输入学号!";JOptionPane.showMessageDialog(null,warning,"警告",JOptionPane.WARNING_MESSAGE);}}}(5).显示界面ShowAct类1).成员变量主要成员变量属性描述变量属性变量名称存放“学生”对象的散列表Hashtable基本信息表显示学生基本信息的文本条JTextField学号,姓名,专业,年级,出生,住址,电话2).方法主要方法名称功能备注ShowAct创建学生信息显示界面构造方法actionPerformed处理ActionEvent事件接口方法3).代码classShowActimplementsActionListener{publicvoidactionPerformed(ActionEvente){newStudentShow(file);} }publicclassStudentShowextendsJDialog{Hashtable学生散列表=null;JTextArea显示=null;FileInputStreaminOne=null;ObjectInputStreaminTwo=null;Filefile=null;publicStudentShow(Filefile){super(newJFrame(),"显示对话框");this.file=file;显示=newJTextArea(16,30);try{inOne=newFileInputStream(file);inTwo=newObjectInputStream(inOne);学生散列表=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exceptionee){}if(学生散列表.isEmpty())显示.append("目前还没有学生的信息记录!n");else{显示.setText("学号姓名性别专业年级出生电话住址n");for(Enumerationenm=学生散列表.elements();enm.hasMoreElements();){Studentstu=(Student)enm.nextElement();Stringsex="";if(stu.getSex().equals("男"))sex="男";elsesex="女";Stringstr=stu.getNumber()+","+stu.getName()+","+sex+","+stu.getSpecialty()+","+stu.getGrade()+","+stu.getBorth()+","+stu.getPhonenumber()+","+stu.getAddress()+"n";显示.append(str);}}JScrollPanescroll=newJScrollPane(显示); Containercon=getContentPane();con.add("Center",scroll);con.validate();setVisible(true);setBounds(200,200,400,300);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){setVisible(false);}});}}2.Student.java1).成员变量主要成员变量描述变量属性变量名称学号StringNumber姓名StringName性别StringSex专业StringSpecialty年级StringGrade出生StringBorth住址StringAddress电话StringPhonenumber2).方法主要方法名称功能SetNumber设置学号GetNumber获取学号SetName设置姓名GetName获取姓名SetSex设置性别GetSex获取性别SetSpecialty设置专业GetSpecialty获取专业SetGrade设置年级GetGrade获取年级SetBorth设置出生GetBorth获取出生SetAddress设置住址 GetAddress获取住址SetPhonenumber设置电话GerPhonenumber获取电话3).代码importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.io.*;importjava.util.*;publicclassStudentimplementsjava.io.Serializable{Stringnumber,name,specialty,grade,borth,sex,address,phonenumber;publicStudent(){};publicvoidsetNumber(Stringnumber){this.number=number;}publicStringgetNumber(){returnnumber;}publicvoidsetName(Stringname){this.name=name;}publicStringgetName(){returnname;}publicvoidsetSex(Stringsex){this.sex=sex;}publicStringgetSex(){returnsex;}publicvoidsetSpecialty(Stringspecialty){this.specialty=specialty;}publicStringgetSpecialty(){returnspecialty;}publicvoidsetGrade(Stringgrade){this.grade=grade;}publicStringgetGrade(){returngrade;}publicvoidsetBorth(Stringborth){this.borth=borth;}publicStringgetBorth(){returnborth;}publicvoidsetAddress(Stringaddress){this.address=address;}publicStringgetAddress(){returnaddress;}publicvoidsetPhonenumber(Stringphonenumber){this.phonenumber=phonenumber;}publicStringgetPhonenumber(){returnphonenumber;}}

最近下载