下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、JAVA员工管理系统实验报告姓名:张旭冉学号: 10105010117班级:信 10-1北方工业大学理学院信息与计算科学系2013 年 12 月 17 日员工管理系统、实验目的通过该课程设计,使同学们进一步理解概JAVA 的基本概念、理论和方法,初步掌握 JDK、Eclipse 的调试和应用,以及程序中错误的解决方法,明确 JAVA 在实际程序设计中的应用。使课堂中学习到理论得到应用,练习文件形式在JAVA 程序设计中的应用。二、实验内容A. 设计题目:员工管理系统 设计要求:(1)完成员工信息的添加、删除、查询、修改功能(2)使用用户界面操作(3)使用文件形式完成 设计思路:首先设计界面进入
2、面板,在面板中添加菜单选项,并将要实现的功能选项添加 其中,然后对这些选项实施监听,实现其功能。通过文件类型知识的应用,实现对员工信 息的管理。B. 概要设计 面板设计:首先设计一个容器,然后再容器中添加菜单,在菜单中添加选项,并在容器中加入面板,面板布局设置为 CardLayout ,最后将面板添加进容器。功能实现:在录入、查询、修改和删除界面中使用 JButton 、JLabel 、ButtonGroup 、JRadioButton 、JTextField 、 Choice 为界面中加入相应的组件,并对其进行监听,同时附 加了文件流的处理。C. 详细设计1、定义员工类:public cla
3、ss Employee implements java.io.SerializableString number,name,discipling,grade,borth,sex;public Employee()public void setNumber(String number)this.number=number;public String getNumber()return number;public void setName(String name)=name; public String getName()return name;public void setDi
4、scipling(String discipling) this.discipling=discipling;public String getDisciping()return discipling;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;public void setSex(Str
5、ing sex)this.sex=sex;public String getSex()return sex;2、主程序: import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.Hashtable;public class EmployeeManager extends JFrame implements ActionListenerEmployeeSituationModifySituationInquestDeleteJMenuBar bar;基本信息录
6、入 =null;基本信息修改 =null;基本信息查询 =null;基本信息删除 =null;JMenu fileMenu;JMenuItem 录入 , 修改 , 查询 , 删除 ;Container con=null;Hashtable 基本信息 =null;File file=null;CardLayout card=null;JLabel label=null;JPanel pCenter;public EmployeeManager()录入 =new JMenuItem( 录入员工基本信息修改 =new JMenuItem( 修改员工基本信息查询 =new JMenuItem( 查询员
7、工基本信息删除 =new JMenuItem( 删除员工基本信息bar=new JMenuBar();fileMenu=new JMenu( 菜单选项 ); fileMenu.add( 录入 );fileMenu.add( 修改 );fileMenu.add( 查询 );fileMenu.add( 删除 );bar.add(fileMenu);setJMenuBar(bar);label=new JLabel( 欢迎进入员工信息管理系统 ,JLabel.CENTER);label.setFont(newFont(SansSerif,Font.BOLD+Font.ITALIC,25);label
8、.setForeground(Color.red);基本信息 =new Hashtable();录入 .addActionListener(this);修改 .addActionListener(this);查询 .addActionListener(this);删除 .addActionListener(this);card=new CardLayout();con=getContentPane();pCenter=newJPanel();pCenter.setLayout(card);pCenter.setBackground(Color.yellow); file=new File( 基
9、本信息 .txt);if(!file.exists() ) )tryFileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out);objectOut.writeObject( 基本信息 );objectOut.close(); out.close();catch(IOException e) 基本信息录入 =new EmployeeSituation(file); 基本信息修改 =newModifySituation(file);基本信息查询 =n
10、ew Inquest(this,file); 基本信息删除 =new Delete(file);pCenter.add( 欢迎语界面 ,label); pCenter.add( 录入界面 , 基本信息录入 ); pCenter.add( 修改界面 , 基本信息修改 ); pCenter.add( 删除界面 , 基本信息删除 ); con.add(pCenter,BorderLayout.CENTER);con.validate();addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)Syste
11、m.exit(0););setVisible(true); setBounds(100,50,420,380); validate();public void actionPerformed(ActionEvent e)if(e.getSource()= 录入 )card.show(pCenter,录入界面 );else if(e.getSource()=修改 )card.show(pCenter,修改界面);else if(e.getSource()=查询)基本信息查询.setVisible(true);else if(e.getSource()=删除)card.show(pCenter,删
12、除界面);public static void main(String args)new EmployeeMa nager();3、实现员工信息的录入:import java.awt.*;import java.awt.eve nt.*;import javax.swi ng.*;import java.io.*;import java.util.*;public class EmployeeSituati on exte nds JPa nel impleme nts Actio nListe ner Hashtable 基本信息表=n ull;JTextField 员工号,姓名,工资;Ch
13、oice 部门;JRadioButton男,女;Employee 员工 =nu II;Butt on Group group=n ull;JButton 录入,重置;File In putStream inOne=n ull;ObjectI nputStream in Two=n ull;FileOutputStream out One=n ull;ObjectOutputStream outTwo=n ull;File file=n ull;public EmployeeSituation(File file)this.file=file;员工号=new JTextField(10); 姓名
14、=new JTextField(10);部门 =new Choice();部门.add(”请选择”);部门 .add( 研发部 ); 部门 .add( 销售部 );部门 .add( 人事部 );部门 .add( 安全部 );工资 =new JTextField(10);group=new ButtonGroup();男=n ew JRadioButto n(” 男 ”,true);女= =门门 ew JRadioButto n(”女false);group.add( 男); group.add( 女);录入 =new JButton( 录入 ); 重置 =new JButton( 重置 );
15、录入 .addActionListener(this); 重置 .addActionListener(this); Boxbox1=Box.createHorizontalBox(); box1.add(new JLabel( 员工号 :,JLabel.CENTER); box1.add( 员工号 );Box box2=Box.createHorizontalBox();box2.add(new JLabel(姓名:,JLabel.CENTER); box2.add( 姓名 );Box box3=Box.createHorizontalBox();box3.add(new JLabel( 性别
16、:,JLabel.CENTER); box3.add( 男);box3.add( 女);Box box4=Box.createHorizontalBox(); box4.add(new JLabel( 部门 :,JLabel.CENTER); box4.add( 部门 );Box box6=Box.createHorizontalBox(); box6.add(new JLabel(,JLabel.CENTER);Box box5=Box.createHorizontalBox();box5.add(new JLabel( 工资:,JLabel.CENTER); box5.add( 工资 );
17、Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2);boxH.add(box3); boxH.add(box5); boxH.add(box6); boxH.add(box4);boxH.add(Box.createVerticalGlue();JPanel pCenter=new JPanel(); pCenter.add(boxH);pCenter.setBackground(Color.yellow); setLayout(new BorderLayout();add(pCenter,BorderLayout.
18、CENTER); JPanel pSouth=new JPanel();pSouth.add( 录入 ); pSouth.add( 重置 );pSouth.setBackground(Color.yellow);add(pSouth,BorderLayout.SOUTH); validate();public void actionPerformed(ActionEvent e)if(e.getSource()=录入 )String number=;number= 员工号 .getText();if(number.length()0)tryinOne=new FileInputStream(f
19、ile);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);elseString m=基本信息将被录入 !;int ok=JOptionPane.showC
20、onfirmDialog(this,m,JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);if(ok=JOptionPane.YES_OPTION) String name= 姓名 .getText();String discipling= 部门 .getSelectedItem();String grade= 工资 .getText();String sex=null;if( 男 .isSelected(), 请到修改页面修改 !;警告确认sex=男 .getText();elsesex= 女 .getText();员工 =
21、new Employee();员工 .setNumber(number);员工 .setName(name);员工 .setDiscipling(discipling);员工 .setGrade(grade);员工 .setSex(sex);tryoutOne=new FileOutputStream(file); outTwo=newObjectOutputStream(outOne); 基本信息表 .put(number, 员工 );outTwo.writeObject( 基本信息表 );outTwo.close();outOne.close();员工号 .setText(null);姓名
22、 .setText(null);工资 .setText(null);catch(Exception ee)System.out.println(ee);elseString warning=必须要输入员工号 !;JOptionPane.showMessageDialog(this,warning,JOptionPane.WARNING_MESSAGE);if(e.getSource()= 重置 )员工号 .setText(null);姓名 .setText(null);部门 .remove( 部门 .getSelectedIndex();!(linu);xauas-聂工4、实现员工信息的修改:
23、import java.awt.*;import java.awt.eve nt.*;import javax.swi ng.*;import java.io.*;import java.util.*;public class ModifySituation extends JPanel implements ActionListener Hashtable 基本信息表=n ull;JTextField 员工号,姓名,工资;Choice 部门;JRadioButton 男,女;Butt on Group group=n ull;JButton 开始修改,录入修改,重置;File In putS
24、tream inOne=n ull;ObjectI nputStream in Two=n ull;FileOutputStream out One=n ull;ObjectOutputStream outTwo=n ull;File file=n ull;public ModifySituatio n(File file)this.file=file; 员工号 =new JTextField(10); 姓名 =newJTextField(10); 部门 =new Choice();部门.add(”请选择”);部门 .add( 研发部 ); 部门 .add( 销售部 );部门 .add( 人事
25、部 );部门 .add( 安全部 );工资 =newJTextField(10);group=new ButtonGroup();男=n ew JRadioButto n(” 男 ”,true);女= =门门 ew JRadioButto n(” 女false); group.add(男);group.add(女);开始修改 =new JButton( 开始修改 );录入修改 =new JButton( 录入修改 ); 录入修改 .setEnabled(false);重置 =new JButton( 重置 ); 员工号 .addActionListener(this); 开始修改 .addAc
26、tionListener(this); 录入修改 .addActionListener(this);重置 .addActionListener(this); Boxbox1=Box.createHorizontalBox();box1.add(new JLabel( 输入要修改信息的员工号box1.add( 员工号 );box1.add( 开始修改 );Box box2=Box.createHorizontalBox();box2.add(new JLabel(姓名:,JLabel.CENTER);box2.add( 姓名 );Box box3=Box.createHorizontalBox(
27、);box3.add(new JLabel(性别:,JLabel.CENTER);box3.add( 男);box3.add( 女);Box box4=Box.createHorizontalBox();box4.add(new JLabel( 部门 :,JLabel.CENTER); box4.add( 部门 );Box box6=Box.createHorizontalBox(); box6.add(new JLabel(,JLabel.CENTER);Box box5=Box.createHorizontalBox();box5.add(new JLabel(工资:,JLabel.CEN
28、TER);box5.add( 工资 );Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box5);boxH.add(box6);:,JLabel.CENTER);boxH.add(box4);boxH.add(Box.createVerticalGlue();JPanel pCenter=new JPanel();pCenter.add(boxH);pCenter.setBackground(Color.yellow);setLayout(new BorderLayo
29、ut();add(pCenter,BorderLayout.CENTER);JPanel pSouth=new JPanel();pSouth.add( 录入修改 );pSouth.add( 重置 );pSouth.setBackground(Color.yellow);add(pSouth,BorderLayout.SOUTH);validate();public void actionPerformed(ActionEvent e)if(e.getSource()= 开始修改 |e.getSource()= 员工号 )String number=;number =员工号.getText()
30、;if(number.length()0)try inOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);基本信息表 =(Hashtable)inTwo.readObject();inOne.close();inTwo.close();catch(Exception ee)if(基本信息表 .containsKey(number)录入修改 .setEnabled(true);Employee stu=(Employee)基本信息表 .get(number);姓名 .setText(stu.getName();部门 .
31、getSelectedItem();工资 .setText(stu.getGrade();if(stu.getSex().equals(男 )男.setSelected(true);else女.setSelected(true);else录入修改 .setEnabled(false);String warning= 该员工号不存在 !;JOptionPane.showMessageDialog(this,warning,JOptionPane.WARNING_MESSAGE); 员工号 .setText(null);姓名 .setText(null);部门 .remove( 部门 .getSe
32、lectedItem(); 工资 .setText(null);else录入修改 .setEnabled(false);String warning= 必须要输入员工号 !;JOptionPane.showMessageDialog(this,warning,JOptionPane.WARNING_MESSAGE); 员工号 .setText(null);姓名 .setText(null);部门 .remove( 部门 .getSelectedItem();工资 .setText(null);else if(e.getSource()= 录入修改 )String number=;number
33、=员工号.getText();if(number.length()0)try inOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);基本信息表 =(Hashtable)inTwo.readObject();inOne.close();警告inTwo.close(); catch(Exception ee)if( 基本信息表 .containsKey(number)String question=息吗?;JOptionPane.showMessageDialog(this,question,JOptionPane.Q
34、UESTION_MESSAGE);String m=基本信息将被修改 !;int ok=JOptionPane.showConfirmDialog(this,m,JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);if(ok=JOptionPane.YES_OPTION)String name=String discipling=String grade=String sex=null;if(该员工基本信息已存在, 您想修改他 ( 她) 的基本信姓名 .getText();部门 .getSelectedItem();工资 .ge
35、tText();男.isSelected()警告确认sex=else男 .getText();sex=Employee女.getText();员工 =new Employee();员工 .setNumber(number);员工 .setName(name);员工 .setDiscipling(discipling);员工 .setGrade(grade);员工 .setSex(sex);tryoutOne=new FileOutputStream(file);outTwo=new ObjectOutputStream(outOne); 基本信息表 .put(number, 员工 );outT
36、wo.writeObject(基本信息表 );outTwo.close();outOne.close();H4.seHexsu-)八辱役.sefrexsuw八阳三.remove(阳三.gefse-ecCDd-CDmo)八Hwsefrexsu=)八cafch(Exceptonee)宀sysCDmouf.prinf-nCDe)八知克 齊 .sefTinab-ed(fa-se) 八e-seif(okHHJOPfionpane乏OIOPTON)宀知克齊.semnab-edarue)八Jopnonpane.showMessageDia-og(fhis-warning=Jopnonpane.wARN乏GI
37、MESSAGEr知克齊.sefTinab-ed(fa-se)八e-se宀Siringwarning-酋鸯H4=八JOPHOnpane.showMessageDia-og(fhis-warning=Jopnonpane.wARN乏GIMESSAGEr知克齊.sefTinab-ed(fa-se)八if(e.gefsource(llHHw)宀H4seHexsu-)八辱役.sefrexsuw八阳三 .remove(阳三.gefse-ecCDd-CDmo)八Hwsefrexsu=)八輸入要I廉改信息的员工号:OS09010223姓名:陈铁松5、实现员工信息的查询:import java.awt.*;im
38、port java.awt.eve nt.*;import javax.swi ng.*;import java.io.*;import java.util.*;public class Inq uest exte nds JDialog impleme nts Acti on Liste ner Hashtable 基本信息表=n ull;JTextField 员工号,姓名,部门,工资;JRadioButton男,女;JButton 查询;Butt on Group group=n ull;File In putStream inOne=n ull;ObjectI nputStream in
39、 Two=n ull;File file=n ull;public Inquest(JFrame f,File file)super(f,查询对话框 ”,false);this.file=file;员工号=new JTextField(10);查询=new JButton(” 查询);员工号.addActionListener(this);菜单选顷工资:4567确认|x|基亦信島将谴隆改!是COL馳丨最入幔改直置性别:男 O 女部门:查询 .addActionListener(this);姓名 =new JTextField(10);姓名 .setEditable(false);部门 =new
40、 JTextField(10);部门 .setEditable(false);工资 =new JTextField(10);工资 .setEditable(false);男=n ew JRadioButto n(” 男false);女= =门门 ew JRadioButto n(”女false);group=new ButtonGroup();group.add( 男 );group.add( 女);Box box1=Box.createHorizontalBox();box1.add(new JLabel( 输入要查询的员工号 :,JLabel.CENTER); box1.add( 员工号
41、);box1.add( 查询 );Box box2=Box.createHorizontalBox();box2.add(new JLabel( 姓名 :,JLabel.CENTER); box2.add( 姓名 );Box box3=Box.createHorizontalBox();box3.add(new JLabel( 性别 :,JLabel.CENTER);box3.add( 男 );box3.add( 女);Box box4=Box.createHorizontalBox();box4.add(new JLabel( 部门 :,JLabel.CENTER);box4.add( 部门
42、 );Box box5=Box.createHorizontalBox();box5.add(new JLabel( 工资 :,JLabel.CENTER); box5.add( 工资 );Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box5);boxH.add(box4);boxH.add(Box.createVerticalGlue();JPanel pCenter=new JPanel(); pCenter.add(boxH);pCenter.setBackg
43、round(Color.green);Container con=getContentPane();con.add(pCenter,BorderLayout.CENTER);con.validate();setVisible(false);setBounds(100,200,360,270);addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)setVisible(false); );public void actionPerformed(ActionEvent e)姓名 .setText(n
44、ull);部门 .setText(null);工资 .setText(null);if(e.getSource()=查询 |e.getSource()= 员工号 )String number=;number= 员工号 .getText();if(number.length()0)try inOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);基本信息表 =(Hashtable)inTwo.readObject();inOne.close();inTwo.close();catch(Exception ee)if( 基
45、本信息表 .containsKey(number)Employee stu=(Employee) 基本信息表 .get(number); 姓名 .setText(stu.getName();部门 .setText(stu.getDisciping(); 工资 .setText(stu.getGrade();if(stu.getSex().equals(男 )男 .setSelected(true);else女 .setSelected(true);elseStri ng warni ng=该员工号不存在!;JOpti onPan e.showMessageDialog(this,war nin
46、 g,”,JOptio nPan e.WARNING_MESSAGE);elseStri ng warni ng=必须要输入员工号 !;JOpti onPan e.showMessageDialog(this,war nin g,JOptio nPan e.WARNING_MESSAGE);6、实现员工信息的删除: import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class Delete extends JPanel impleme
47、nts ActionListenerHashtable 基本信息表 =null; JTextField 员工号 ,姓名 ,部门,工资;JRadioButton 男 , 女 ;JButton 删除 ; ButtonGroup group=null; FileInputStream inOne=null;ObjectInputStream inTwo=null; FileOutputStream outOne=null;警告警告ObjectOutputStream outTwo=null; File file=null; public Delete(File file)this.file=file
48、; 员工号 =new JTextField(10); 删除 =new JButton( 删除 );员工号 .addActionListener(this); 删除 .addActionListener(this); 姓名=new JTextField(10); 姓名 .setEditable(false); 部门 =newJTextField(10); 部门 .setEditable(false); 工资 =new JTextField(10); 工资 .setEditable(false); 男 =new JRadioButton( 男 ,false); 女 =newJRadioButton
49、( 女 ,false); group=new ButtonGroup(); group.add( 男 );group.add( 女 );Box box1=Box.createHorizontalBox(); box1.add(new JLabel( 输入要删除的学号 :,JLabel.CENTER); box1.add( 员工号 );box1.add( 删除 );Box box2=Box.createHorizontalBox(); box2.add(new JLabel( 姓名 :,JLabel.CENTER); box2.add( 姓名 );Box box3=Box.createHoriz
50、ontalBox(); box3.add(new JLabel( 性别 :,JLabel.CENTER); box3.add( 男 );box3.add( 女 );Box box4=Box.createHorizontalBox();box4.add(new JLabel( 部门 :,JLabel.CENTER); box4.add( 部门 );Box box6=Box.createHorizontalBox(); box6.add(new JLabel(,JLabel.CENTER);Box box5=Box.createHorizontalBox(); box5.add(new JLabel( 工资 :,JLabel.CENTER); box5.add( 工资 );Box boxH=Box.createVerticalBox(); boxH.add(box1);boxH.add(box2);boxH.add(box3); boxH.add(box5);boxH.add(box6); boxH.add(box4);boxH.add(Box.createVe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电脑监控施工方案(3篇)
- 消防电路施工方案(3篇)
- 明涵施工方案(3篇)
- 明园活动策划方案(3篇)
- 换热器设计施工方案(3篇)
- 保险业务运营管理指南(标准版)
- 绿云餐饮系统培训
- 中国的文化制度
- 2025年高职有机化工生产技术(有机化工应用)试题及答案
- 2025年大学四年级(财务管理)高级财务管理试题及答案
- 餐巾折花教学课件
- 商代方国考古探讨
- 北京大兴机场案例赏析64课件
- DBJT15-140-2018 广东省市政基础设施工程施工安全管理标准
- DB43∕T 1859-2020 研学产品设计与评价规范
- 医务部会议管理制度范本
- Q-JJJ 9002-2025 铁路建设项目安全穿透式管理实施指南
- 员工韧性能力培养-洞察及研究
- alc墙板安装培训课件
- 2025年7月辽宁省普通高中学业水平合格性考试生物试题(原卷版)
- 抖音直播违规考试题及答案
评论
0/150
提交评论