1、负责创建存放学生信息的对象。三:详细设计1 主类StudentManager.java1).成员变量主要成员变量成员变量描述变量类型变量名称基本信息录入界面基本信息修改界面基本信息查询界面基本信息删除界面菜单选项 存基本信息的散列表存放散列表的文件StudentSituationModifySituationInquestDeleteJMenuItemHashtableFile基本信息录入基本信息修改基本信息查询基本信息删除录入,修改,查询,删除基本信息file2).方法主要方法名称功能备注StudentManageractionPerformedmain创建程序主窗口 处理ActionEve
2、nt事件程序开始运行构造方法接口方法3).代码StudentManager.javaimport java.awt.*。import java.awt.event.*。import javax.swing.*。import java.io.*。import java.util.Hashtable。public class StudentManager extends JFrame implements ActionListener StudentSituation 基本信息录入=null。 ModifySituation 基本信息修改=null。 Inquest 基本信息查询=null。 De
3、lete 基本信息删除=null。 JMenuBar bar。 JMenu fileMenu。 JMenuItem 录入,修改,查询,删除,退出。 Container con=null。 Hashtable 基本信息=null。 File file=null。 CardLayout card=null。 JLabel label。 JPanel pCenter。 public StudentManager() setTitle(欢迎进入班级管理系统)。 录入=new JMenuItem(录入学生基本信息 修改=new JMenuItem(修改学生基本信息 查询=new JMenuItem(查询
4、学生基本信息 删除=new JMenuItem(删除学生基本信息 退出=new JMenuItem(退出本系统 退出.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) System.exit(0)。 )。 bar=new JMenuBar()。 fileMenu=new JMenu(菜单选项 fileMenu.add(录入)。 fileMenu.addSeparator()。 fileMenu.add(修改)。 fileMenu.add(查询)。 fileMenu.add(
5、删除)。 fileMenu.add(退出)。 bar.add(fileMenu)。 setJMenuBar(bar)。 label=new JLabel(欢迎进入班级管理系统!,label.CENTER)。 label.setFont(new Font(隶书,Font.BOLD,30)。 label.setForeground(Color.blue)。 基本信息=new Hashtable()。 录入.addActionListener(this)。 修改.addActionListener(this)。 查询.addActionListener(this)。 删除.addActionList
6、ener(this)。 card=new CardLayout()。 con=getContentPane()。 pCenter=new JPanel()。 pCenter.setLayout(card)。 file=new File(学生基本信息.txt if(!file.exists() try FileOutputStream out=new FileOutputStream(file)。 ObjectOutputStreamobjectOut=new ObjectOutputStream(out)。 objectOut.writeObject(基本信息)。 objectOut.clos
7、e()。 out.close()。 catch(IOException e) 基本信息录入=new StudentSituation(file)。 基本信息修改=new ModifySituation(file)。 基本信息查询=new Inquest(this,file)。 基本信息删除=new Delete(file)。 pCenter.add(欢迎语界面,label)。录入界面,基本信息录入)。修改界面,基本信息修改)。删除界面,基本信息删除)。 con.add(pCenter,BorderLayout.CENTER)。 con.validate()。 addWindowListener
8、(new WindowAdapter() public void windowClosing(WindowEvent e) setVisible(true)。 setBounds(100,50,420,380)。 validate()。 public void actionPerformed(ActionEvent e) if(e.getSource()=录入) card.show(pCenter, else if(e.getSource()=修改) else if(e.getSource()=查询) 基本信息查询.setVisible(true)。 else if(e.getSource()
9、=删除) public static void main(String args) new StudentManager()。2.录入界面主要成员变量属性描述存放“学生”对象的散列表输入学生基本信息的文本存放学生信息的对象JTextFieldStudent基本信息表学号,姓名,所学专业,家庭住址,出生学生创建学生信息录入界面处理ActionEvent事件StudentSituation.javaimport java.util.*。public class StudentSituation extends JPanel implements ActionListener Hashtable 基
10、本信息表=null。 JTextField 学号,姓名,所学专业,家庭住址,出生。 JRadioButton 男,女。 Student 学生=null。 ButtonGroup group=null。 JButton 录入,重置。 FileInputStream inOne=null。 ObjectInputStream inTwo=null。 FileOutputStream outOne=null。 ObjectOutputStream outTwo=null。 public StudentSituation(File file) this.file=file。 学号=new JTextF
11、ield(10)。 姓名=new JTextField(10)。所学专业=new 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(重置 重置.addActionListener(this)。Box box1=Box.createHori
12、zontalBox()。 box1.add(new JLabel(学号:,JLabel.CENTER)。 box1.add(学号)。Box box2=Box.createHorizontalBox()。 box2.add(new JLabel(姓名: box2.add(姓名)。Box box3=Box.createHorizontalBox()。 box3.add(new JLabel(性别: box3.add(男)。 box3.add(女)。Box box4=Box.createHorizontalBox()。 box4.add(new JLabel(所学专业: box4.add(所学专业)
13、。Box box5=Box.createHorizontalBox()。 box5.add(new JLabel(家庭住址: box5.add(家庭住址)。Box box6=Box.createHorizontalBox()。 box6.add(new JLabel(出生: box6.add(出生)。 Box boxH=Box.createVerticalBox()。 boxH.add(box1)。 boxH.add(box2)。 boxH.add(box3)。 boxH.add(box4)。 boxH.add(box5)。 boxH.add(box6)。 boxH.add(Box.creat
14、eVerticalGlue()。 JPanel pCenter=new JPanel()。 pCenter.add(boxH)。 setLayout(new BorderLayout()。 add(pCenter,BorderLayout.CENTER)。 JPanel pSouth=new JPanel()。 pSouth.add(录入)。 pSouth.add(重置)。 add(pSouth,BorderLayout.SOUTH)。 String number=。 number=学号.getText()。 if(number.length()0) try inOne=new FileInp
15、utStream(file)。 inTwo=new ObjectInputStream(inOne)。 基本信息表=(Hashtable)inTwo.readObject()。 inOne.close()。 inTwo.close()。 catch(Exception ee) if(基本信息表.containsKey(number) String warning=该生基本信息已存在,请到修改页面修改!JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE)。 else String m=基本信息将被录入
16、! intok=JOptionPane.showConfirmDialog(this,m,确认,JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE)。 if(ok=JOptionPane.YES_OPTION) String name=姓名.getText()。 String discipling=所学专业.getText()。 String grade=家庭住址.getText()。 String borth=出生.getText()。 String sex=null。 if(男.isSelected() sex=男.getTe
17、xt()。 sex=女.getText()。 学生=new Student()。 学生.setNumber(number)。 学生.setName(name)。 学生.setDiscipling(discipling)。 学生.setGrade(grade)。 学生.setBorth(borth)。 学生.setSex(sex)。 outOne=new FileOutputStream(file)。 outTwo=new ObjectOutputStream(outOne)。 基本信息表.put(number,学生)。 outTwo.writeObject(基本信息表)。 outTwo.clo
18、se()。 outOne.close()。 学号.setText(null)。 姓名.setText(null)。所学专业.setText(null)。家庭住址.setText(null)。 出生.setText(null)。 System.out.println(ee)。必须要输入学号! JOptionPane.showMessageDialog(this,warning,警告 if(e.getSource()=重置)3.查询界面存放“学生”对象的散表显示学生基本信息的文本创建查询界面Inquest.javapublic class Inquest extends JDialog imple
19、ments ActionListener JButton 查询。 public Inquest(JFrame f,File file) super(f,查询对话框 查询=new JButton(查询 学号.addActionListener(this)。 姓名.setEditable(false)。所学专业.setEditable(false)。家庭住址.setEditable(false)。 出生.setEditable(false)。输入要查询的学号: box1.add(查询)。 Container con=getContentPane()。 setVisible(false)。 setBounds(100,200,360,270)。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1