版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
员号员号员号业程 20119——201112月算机科制。。。。指导教师签字: 日期:指导教师语: 指导教师签字: 日期:、硬件JAVAMyEclipse6进度划起止日期 工作内容 备注201110201112
编写一个管理学籍数据库参考文献、资料索引序号 文献、资料名称 编着者 出版单位<Java序> 高晓黎刘博主编, 清华大学出版社《Java思想》《Javajava》6java。类之间的主要关如图所示。StudentManager( StudentManager( 主)StudentSituatiInquesDeleteModifySituationStudenStudentManager.javajava含有main开始执行。StudentSituation.java存放生信息对象。具体设计StudentManager1.成员变量(见下表)要成员变量(属性)成员变量描述变量型名称基本信息录入界面StudentSituation基本信息录入基本信息修改界面ModifySituation基本信息修改基本信息查询界面Inquest基本信息查询基本信息删除界面Delete基本信息删除菜单选项JmenuItem录入,修改,查询,删除存放基本信息散列表Hashtable基本信息存放散列表Filefile2.方法(见下表)要方法名称功能备注StudentManager程序构造方法actionPerformed处ActionEvent件接方法main程序开始运行3.代码StudentManager.javaimportjava.awt.*;importjavax.swing.*;importjava.io.*;publicclassStudentManagerextendsJFrameimplementsActionListener{StudentSituation=null;ModifySituation=null;InquestDelete JMenuBarbar;JMenufileMenu;JMenuItem;Containercon=null;Hashtable=null; //Filefile=null; 件CardLayoutcard=null; //卡片式布局JLabellabel=null; JPanelpCenter;publicStudentManager(){=newJMenuItem("学生");=newJMenuItem("学生");=newJMenuItem("学生");=newJMenuItem("学生");bar=newJMenuBar();fileMenu=newJMenu("fileMenu.add();fileMenu.add();fileMenu.add();fileMenu.add();bar.add(fileMenu);setJMenuBar(bar);label=newJLabel("欢迎使用学生",JLabel.CENTER);label.setFont(newFont("TimesRoman",Font.BOLD,24));label.setForeground(Color.red);=new.addActionListener(this);.addActionListener(this);.addActionListener(this);.addActionListener(this);card=newCardLayout();con=getContentPane();pCenter=newJPanel();pCenter.setLayout(card);file=newFile(".txt");if(!file.exists()){try{FileOutputStreamout=newFileOutputStream(file);ObjectOutputStreamobjectOut=newObjectOutputStream(out););objectOut.close();out.close();}catch(IOExceptione){}}=newStudentSituation(file);=newModifySituation(file);=newInquest(this,file);=newDelete(file);pCenter.add("",label);pCenter.add(");pCenter.add(");pCenter.add(");con.add(pCenter,BorderLayout.CENTER);con.validate();addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});setVisible(true);setBounds(100,50,420,380);validate();}publicvoidactionPerformed(ActionEvente){if(e.getSource()==){card.show(pCenter,"}elseif(e.getSource()==){card.show(pCenter,"}elseif(e.getSource()==){ .setVisible(true);}elseif(e.getSource()==){card.show(pCenter,"}}publicstaticvoidmain(Stringargs[]){newStudentManager();}}StudentSituation1述 型 “学生”对象的散列Hashtable 基本信息表输学生基本信息的文本条 JtextField 学号姓专业年级出生学生信息的对象 Student 学2方法称 功能 备注StudentSituation 创建学生面 构造方actionPerformed 处理ActionEvent件 接口方3StudentSituation.javaimportjava.awt.*;importjavax.swing.*;importjava.io.*;importjava.util.*;publicclassStudentSituationextendsJPanelimplementsActionListener{Hashtable基本信息=null; JTextField学号姓专业年级出; //输基本信息的文本条JRadioButton男女;Student ButtonGroupgroup=null;JButtonFilefile=null; //散列的文件publicStudentSituation(Filefile){this.file=file;=newJTextField(10);=newJTextField(10);=newJTextField(10);=newJTextField(10);=newJTextField(10);group=new男=newJRadioButton("男",true);女=newJRadioButton("女",false);group.add(男);=newJButton("=newJButton(.addActionListener(this);.addActionListener(this);Boxbox1=Box.createHorizontalBox(); //6box1.add(newJLabel(":",JLabel.CENTER));Boxbox2=Box.createHorizontalBox();box2.add(newJLabel(":",JLabel.CENTER));box2.add();Boxbox3=Box.createHorizontalBox();box3.add(newJLabel(":",JLabel.CENTER));box3.add();Boxbox4=Box.createHorizontalBox();box4.add(newJLabel(":",JLabel.CENTER));box4.add();Boxbox5=Box.createHorizontalBox();box5.add(newJLabel(":",JLabel.CENTER));box5.add();Boxbox6=Box.createHorizontalBox();box6.add(newJLabel(":",JLabel.CENTER));box6.add();//Box6BoxBoxboxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box4);boxH.add(box5);boxH.add(box6);boxH.add(Box.createVerticalGlue()); //BoxJPanelpCenter=newJPanel();pCenter.add(boxH);setLayout(newBorderLayout());add(pCenter,BorderLayout.CENTER);JPanelpSouth=newJPanel();pSouth.add(录入);pSouth.add();validate();}publicvoidactionPerformed(ActionEvente){if(e.getSource()==录入){Stringnumber="";if(number.length()>0) //如果已输入{try{
inOne=newFileInputStream(file);inTwo=new基本信息表=(Hashtable)inTwo.readObject();//首先到文件中读取inOne.close();inTwo.close();}
Hashtable//",JOptionPane.
catch(Exceptionee){}if(.containsKey(number))//{ //Stringwarning="JOptionPane.showMessageDialog(this,warning," 警WARNING_MESSAGE);}else //{Stringint ok=JOptionPane.showConfirmDialog(this,m," ",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);if(ok==JOptionPane.YES_OPTION){Stringname=.getText();Stringdiscipling.getText();Stringgrade=.getText();Stringborth=.getText();Stringsex=null;if(男.isSelected()){}else{}
=newStudent();.setName(name);.setGrade(grade);.setSex(sex);try{outOne=newFileOutputStream(file);outTwo=newObjectOutputStream(outOne);.put(number,);outTwo.writeObject();outTwo.close();.setText(null);}else
}catch(Exceptionee){}}}//Stringwarning="WARNING_MESSAGE);}}{}}}Inquest1述 型 “”象的散列Hashtable year显示基本信息的文本条 JTextField 2方法称 功能 备注Inquest 创建面 构造方法actionPerformed 处理ActionEvent件 接口方3Inquest.javaimportjava.awt.*;importjavax.swing.*;importjava.io.*;importjava.util.*;publicclassInquestextendsJDialogimplementsActionListener{Hashtable=null; JTextField,业,级,; //显示文本条JRadioButtonFileInputStreaminOne=null;ObjectInputStreamFilefile=null; 文件publicInquest(JFramef,Filefile){super(f,"查询对话",false); 建无模式对话this.file=file;=newJTextField(10);=newJButton(=newJTextField(10);.setEditable(false);=newJTextField(10);=newJTextField(10);=newJTextField(10);男=newJRadioButton("男",false);女=newJRadioButton("女",false);group=newButtonGroup();group.add(男);//6Box组件Boxbox1=Box.createHorizontalBox();box1.add(newJLabel("输入要查询:",JLabel.CENTER));box1.add();Boxbox2=Box.createHorizontalBox();box2.add(newJLabel(":",JLabel.CENTER));box2.add();Boxbox3=Box.createHorizontalBox();box3.add(newJLabel("性别:",JLabel.CENTER));box3.add(Boxbox4=Box.createHorizontalBox();box4.add(newJLabel("专业:",JLabel.CENTER));box4.add(Boxbox5=Box.createHorizontalBox();box5.add(newJLabel("年级:",JLabel.CENTER));box5.add(Boxbox6=Box.createHorizontalBox();box6.add(newJLabel("出:",JLabel.CENTER));box6.add();//Box6BoxboxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box4);boxH.add(box5);boxH.add(box6);boxH.add(Box.createVerticalGlue());//使垂直Box容器内的组件靠上对齐JPanelpCenter=newJPanel();pCenter.add(boxH);Containercon=getContentPane();con.add(pCenter,BorderLayout.CENTER);con.validate();setVisible(false);setBounds(100,200,360,270);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){setVisible(false);}});}publicvoidactionPerformed(ActionEvente){if(e.getSource()==查询||e.getSource()==学号){Stringnumber="";number=学号.getText();if(number.length()>0){try{
inOne=newFileInputStream(file);inTwo=new基本信息表=(Hashtable)inTwo.readObject();//首先到文件中读取//Hashtable对象}catch(Exceptionee){}基本信息表.containsKey(number)) 如果存在该的基本信息{Studentstu=(Student)基本信息表.get(number);.setText(stu.getName());.setText(stu.getGrade());.setText(stu.getBorth());if(stu.getSex().equals("{.setSelected(true);}else{}else
.setSelected(true);}{Stringwarning="JOptionPane.showMessageDialog(this,warning,"",JOptionPane.WARNING_MESSAGE);}}else{//Stringwarning="JOptionPane.showMessageDialog(this,warning,"",JOptionPane.WARNING_MESSAGE);}}}}1述 型 “”象的散列Hashtable 基本信息表基本信息的文本条 JTextField 2方法称 功能 备注ModifySituation 创建信息面 构造方法actionPerformed 处理ActionEvent件 接口方3ModifySituation.javaimportjava.awt.*;importjavax.swing.*;importjava.io.*;importjava.util.*;publicclassModifySituationextendsJPanelimplementsActionListener{Hashtable=null; JTextField,业,级,; //输入文本条JRadioButton开始修改,录入修改,重置;FileInputStreaminOne=null;ObjectInputStreaminTwo=null;FileOutputStreamoutOne=null;ObjectOutputStreamoutTwo=null;Filefile=null; //文件publicModifySituation(Filefile){this.file=file;=newJTextField(10);=newJTextField(10);=newJTextField(10);=newJTextField(10);=newJTextField(10);group=new男=newJRadioButton("男",true);女=newJRadioButton("女",false);group.add(男);=newJButton(=newJButton(.setEnabled(false);=newJButton(.addActionListener(this);开始修改.addActionListener(this);录入修改.addActionListener(this);重置.addActionListener(this);Boxbox1=Box.createHorizontalBox();6组件box1.add(newJLabel("输入要修改:",JLabel.CENTER));box1.add();box1.add(开始修改);Boxbox2=Box.createHorizontalBox();box2.add(newJLabel(":",JLabel.CENTER));box2.add();Boxbox3=Box.createHorizontalBox();box3.add(newJLabel("(:",JLabel.CENTER));box3.add(Boxbox4=Box.createHorizontalBox();box4.add(newJLabel("(:",JLabel.CENTER));box4.add(Boxbox5=Box.createHorizontalBox();box5.add(newJLabel("(:",JLabel.CENTER));box5.add(Boxbox6=Box.createHorizontalBox();box6.add(newJLabel("(:",JLabel.CENTER));box6.add();//Box6BoxboxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box4);boxH.add(box5);boxH.add(box6);boxH.add(Box.createVerticalGlue()); BoxJPanelpCenter=newJPanel();pCenter.add(boxH);setLayout(newBorderLayout());add(pCenter,BorderLayout.CENTER);JPanelpSouth=newJPanel();pSouth.add(录入修改);pSouth.add(重置);add(pSouth,BorderLayout.SOUTH);validate();}publicvoidactionPerformed(ActionEvente){if(e.getSource()==开始修改||e.getSource()==学号){Stringnumber="";number=学号.getText();if(number.length()>0){try{}
inOne=newFileInputStream(file);inTwo=newinOne.close();inTwo.close();catch(Exceptionee){}if(基本信息表.containsKey(number)) //如果存在该的基本信息{录入修改.setEnabled(true);Studentstu=(Student)基本信息表.get(number);.setText(stu.getName());.setText(stu.getBorth());if(stu.getSex().equals("{.setSelected(true);}else{.setSelected(true);}}else //不存在{ //弹出警告对话框录入修改.setEnabled(false);Stringwarning="JOptionPane.showMessageDialog(this,warning," 警 ",JOptionPane.WARNING_MESSAGE);出}}else //学号输入框内容为空,弹出警告对话框{.setEnabled(false);Stringwarning="JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);出}}elseif(e.getSource()==录入修改){Stringnumber="";number=学号.getText();if(number.length()>0){try{inOne=newFileInputStream(file);inTwo=new=(Hashtable)inTwo.readObject();//Hashtable
inOne.close();inTwo.close();}catch(Exceptionee){}在";
if(.containsKey(number)) //{ //Stringquestion=",()JOptionPane.showMessageDialog(this,question,"",JOptionPane.QUESTION_MESSAGE);Stringintok=JOptionPane.showConfirmDialog(this,m," 确 ",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);if(ok==JOptionPane.YES_OPTION){Stringname=.getText();Stringdiscipling=专业.getText();Stringgrade=.getText();Stringborth=.getText();Stringsex=null;if(男.isSelected()){}else{}
文件
Student =newStudent();.setNumber(number);.setName(name);.setGrade(grade);.setSex(sex);try //后学入到散列{outOne=newFileOutputStream(file);outTwo=newObjectOutputStream(outOne);.put(number,学);outTwo.writeObject();outTwo.close();outOne.close();}catch(Exceptionee){}.setEnabled(false);}elseif(ok==JOptionPane.NO_OPTION){}else{
.setEnabled(true);}}else
Stringwarning=",JOptionPane.showMessageDialog(this,warning,.setEnabled(false);}Stringwarning=".setEnabled(false);}}if(e.getSource()==){}}}1述 型 “”象散列Hashtable 显示文条 JTextField 2方法称 功能 备注Delete 创建面 actionPerformed 处理ActionEvent件 3Delete.javaimportjava.awt.*;importjavax.swing.*;importjava.io.*;importjava.util.*;publicclassDeleteextendsJPanelimplementsActionListener{Hashtable=null; JTextField,业,级,; //显示文本条JRadioButtonFileInputStreaminOne=null;ObjectInputStreaminTwo=null;FileOutputStreamoutOne=null;ObjectOutputStreamFilefile=null; //文件publicDelete(Filefile){this.file=file;=newJTextField(10);=newJButton(=newJTextField(10);.setEditable(false);=newJTextField(10);=newJTextField(10);=newJTextField(10);男=newJRadioButton("男",false);女=newJRadioButton("女",false);group=newButtonGroup();group.add(男);Boxbox1=Box.createHorizontalBox()6Box组件box1.add(newJLabel("输入要删除:",JLabel.CENTER));Boxbox2=Box.createHorizontalBox();box2.add(newJLabel(":",JLabel.CENTER));box2.add();Boxbox3=Box.createHorizontalBox();box3.add(newJLabel("性别:",JLabel.CENTER));box3.add(Boxbox4=Box.createHorizontalBox();box4.add(newJLabel(":",JLabel.CENTER));box4.add();Boxbox5=Box.createHorizontalBox();box5.add(newJLabel(":",JLabel.CENTER));box5.add();Boxbox6=Box.createHorizontalBox();box6.add(newJLabel(":",JLabel.CENTER));box6.add();//Box6BoxboxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box4);boxH.add(box5);boxH.add(box6);boxH.add(Box.createVerticalGlue());//使得垂直Box容器内的组件靠上对齐JPanelpCenter=newJPanel();pCenter.add(boxH);setLayout(newBorderLayout());add(pCenter,BorderLayout.CENTER);validate();}publicvoidactionPerformed(ActionEvente){if(e.getSource()==删除||e.getSource()==学号){Stringnumber="";number=学号.getText();if(number.length()>0){Hashtable
try{}
inOne=newFileInputStream(file);inTwo=new基本信息表=(Hashtable)inTwo.readObject();//到文件中读取inOne.close();inTwo.close();已经存在
catch(Exceptionee){}if(基本信息表.containsKey(number)) //如果该的基本信息{Studentstu=(Student)基本信息表.get(number);.setText(stu.getName());.setText(stu.getBorth());if(stu.getSex().equals("
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年碳市场交易风险防控及企业碳资产管理策略题库
- 2026年四好农村路示范创建管理办法及建设管理养护运营实务考核题
- 2026年高新区创新创业大赛题库
- 我最重要的演讲稿英语
- 2026年燃气调压工实操考核及压力调节操作
- 2026年应聘者应具备的财务知识
- 2026年金融投资知识问答手册
- 我所热爱的美食演讲稿
- 留学生回国融资演讲稿
- 2026年英语四级考试全真模拟题集
- 病案管理考核奖惩制度
- 2025年脑机接口技术在睡眠障碍康复中的应用
- 2026年大学生军事理论知识竞赛题库及答案(共80题)
- 2026年贵州贵阳云岩区街道招聘笔试模拟试题附答案
- 《人形机器人技术基础与应用》课件全套 第1-9章-绪论、人形机器人运动学与动力学 -人形机器人运动控制实践
- 班组安全监督员奖惩制度
- 八宝茶课件教学课件
- 考古勘探安全生产制度
- 炼钢厂防混钢制度规范
- 淘宝客培训课件
- 2025考研政治简答题专项卷含答案
评论
0/150
提交评论