版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1 定义职工类:public class Employee impleme nts java.io.SerializableString number,name,discipling,grade,borth,sex;public Employee(public void setNumber(Stri ng nu mberthis .nu mber= nu mber;public String getNumber(retur n nu mber;public void setName(String namethis .n ame=n ame;public String getName(retur
2、n n ame;public void setDiscipli ng(Stri ng discipli ngthis.discipli ng=discipli ng;public String getDiscip ing(retur n discipli ng;public void setGrade(Stri ng gradethis.grade=grade;public String getGrade(return grade;public void setBorth(Stri ng borththis.borth=borth;public String getBorth(return b
3、orth;public void setSex(Stri ng sexthis.sex=sex;public String getSex( return sex;2、主程序:import java.awt.*;import java.awt.eve nt.*;import javax.swi ng.*;import java.io.*;import java.util.Hashtable;public class EmployeeMa nager exte nds JFrame impleme nts Acti on Liste nerEmployeeSituatio n 基本信息录入=nu
4、II;ModifySituatio n基本信息修改=nu II;In quest 基本信息查询=n ull;Delete 基本信息删除=n ull;JMen uBar bar;JMe nu fileMe nu;JMenultem 录入,修改,查询,删除;Container con=n ull;Hashtable 基本信息=n ull;File file=n ull;CardLayout card=n ull;JLabel label=null;JPa nel pCe nter;public EmployeeMa nager(录入=new JMenultem(”录入职工基本信息;修改=new J
5、Menultem(”修改职工基本信息;查询=new JMenultem(”查询职工基本信息 ”删除=new JMenultem(”删除职工基本信息” bar=new JMe nuBar(;fileMenu=new JMenu(” 菜单选项;fileMenu.add(录入;fileMenu.add(修改;fileMenu.add(查询;fileMenu.add(删除;bar.add(fileMe nu;setJMe nuBar(bar;label=new JLabel(欢迎进入职工信息管理系统”,JLabel.CENTER;label.setFont(new Font(SansSerif,Fon
6、t.BOLD+FontTALIC,25;label.setForegro un d(Color.red;基本信息=new Hashtable(;录入.addActionListener(this;修改.addActionListener(this;查询.addActionListener(this;删除.addActionListener(this;card=new CardLayout(;con=getC onten tPa ne(;pCe nter=new JPa nel(;pCe nter.setLayout(card;pCe nter.setBackgro un d(Color.yel
7、low;file=new File(基本信息.txt;if(!file.exists( tryFileOutputStream out=new FileOutputStream(file;ObjectOutputStream objectOut =new ObjectOutputStream(out;objectOut.writeObject(基本信息;objectOut.close(;out.close(;catch(IOExcepti on e基本信息录入=new EmployeeSituation(file;基本信息修改=new ModifySituatio n(file;基本信息查询=
8、new Inq uest(this,file;基本信息删除=new Delete(file;pCenter.add(” 欢迎语界面,label;pCenter.add(” 录入界面,基本信息录入;pCenter.add(”修改界面,基本信息修改;pCenter.add(”删除界面,基本信息删除;con .add(pCe nter,BorderLayout.CENTER;con. validate(;addWi ndowListe ner(new Win dowAdapter(public void wi ndowClos in g(Wi ndowEve nt eSystem.exit(0;se
9、tVisible(true;setBou nds(100,50,420,380;validatedpublic void acti on Performed(Act ion Eve nt eif(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,删除界面;public static void ma
10、in(String argsnew 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 nerHashtable 基本信息表=n ull;JTextField 职工号,姓名,工资;Choice 部门;JRadioButton 男,女;Emp
11、loyee 职工=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 filethis.file=file;职工号=new JTextField(10;姓名=new JTextField(10;咅部门=new Choi
12、ce(;部门.add(请选择;部门.add(”研发部”;部门.add(”销售部;部门.add(”人事部;部门.add(”安全部;工资=new JTextField(10;group=new Butt on Group(;男= =门门 6 可可 JRadioButton(男 ”,true;女= =门门 ew JRadioButto n(” 女false;group.add(男;group.add(女;录入=new JButton(” 录入;重置=new JButton(” 重置;录入.addActionListener(this;重置.addActionListener(this;Box box
13、 仁仁 Box.createHoriz on talBox(;box1.add(new JLabel(职工号:,JLabel.CENTER;box1.add(职工号;Box box2=Box.createHoriz on talBox(;box2.add(new JLabel( 姓名:,JLabel.CENTER;box2.add(姓名;Box box3=Box.createHoriz on talBox(;box3.add(new JLabel( 性别:,JLabel.CENTER;box3.add(男;box3.add(女;Box box4=Box.createHoriz on talBo
14、x(;box4.add(new JLabel( 部门:,JLabel.CENTER;box4.add(部门;Box box6=Box.createHoriz on talBox(;box6.add(new JLabel( ”,JLabel.CENTER;Box box5=Box.createHoriz on talBox(;box5.add(new JLabel(工资:,JLabel.CENTER;box5.add(工资;Box boxH=Box.createVerticalBox(;boxH.add(box1;boxH.add(box2;boxH.add(box3;boxH.add(box5
15、;boxH.add(box6;boxH.add(box4;boxH.add(Box.createVerticalGlue(;JPa nel pCe nter=new JPa nel(;pCe nter.add(boxH;pCe nter.setBackgro un d(Color.yellow;setLayout (new BorderLayout(;add(pCe nter,BorderLayout.CENTER;JPa nel pSouth=new JPa nel(;pSouth.add(录入;pSouth.add(重置;pSouth.setBackgro un d(Color.yello
16、w;add(pSouth,BorderLayout.SOUTH;validate(;public void acti on Performed(Act ion Eve nt eif(e.getSource(= 录入String nu mber=;number=职工号.getText(;if(nu mber.le ngth(0tryinOne=new FilelnputStream(file;in Two=new ObjectI nputStream(i nOne;基本信息表=(Hashtablei nTwo.readObject(;inOn e.close(;in Two.close(;cat
17、ch(Excepti on ee if(基本信息表.containsKey(numberString warning=该职工基本信息已存在,请到修改页面修改!;JOptio nPan e.showMessageDialog(this,warni ng, elseString m=基本信息将被录入!;int ok=JOptio nPan e.showC on firmDialog(this,m,JOptio nPan eNFORMATION_MESSAGE;警告,JOptionPane.WARNING_MESSAGE;确认,JOptionPane.YES_NO_OPTION,if(ok=JOpt
18、io nPan e.YES_OPTIONString name=姓名.getText(;String discipling=咅部门.getSelectedltem(;String grade= 工资.getText(;String sex=n ull;if(男.isSelected(sex=男.getText(;elsesex=女.getText(;职工=new Employee(;职工.setNumber(number;职工.setName(name;职工.setDiscipling(discipling;职工.setGrade(grade;职工.setSex(sex;tryout One=
19、new FileOutputStream(file;outTwo=new ObjectOutputStream(out One; 基本信息表.put(number, 职工;outTwo.writeObject(基本信息表;outTwo.close(;out On e.close(;职工号.setText(null;姓名.setText(null;工资.setText(null;catch(Excepti on eeSystem.out.pri ntln( ee;elseStri ng warni ng=必须要输入职工号!;JOptio nPan e.showMessageDialog(this
20、,warni ng,if(e.getSource(= 重置职工号.setText(null;姓名.setText(null;部门.remove(部门.getSelectedIndex(;工资.setText(null; 4、实现职工信息的修改: import java.awt.*;警告,JOptionPane.WARNING_MESSAGE;import java.awt.eve nt.*;import javax.swi ng.*;import java.io.*;import java.util.*;public class ModifySituation extends JPanel i
21、mplements ActionListenerHashtable 基本信息表=n ull;JTextField 职工号,姓名,工资;Choice 部门;JRadioButton 男,女;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 ModifySitua
22、tion(File filethis.file=file;职工号=new JTextField(10;姓名=new JTextField(10;咅部门=new Choice(;部门.add(请选择;部门.add(研发部;部门.add(销售部;部门.add(”人事部”;部门.add(”安全部;工资=new JTextField(10;group=new Butt on Group(;男= =门门 6 可可 JRadioButton(男 ”,true;女= =门门 ew JRadioButto n(” 女false;group.add(男;group.add(女;开始修改=new JButton(
23、” 开始修改;录入修改=new JButton(” 录入修改;录入修改.setEnabled(false;重置=new JButton(” 重置;职工号.addActionListener(this;开始修改.addActionListener(this;录入修改.addActionListener(this;重置.addActionListener(this;Box box 仁仁 Box.createHoriz on talBox(;box1.add( new JLabel(输入要修改信息的职工号box1.add(职工号;box1.add(开始修改;Box box2=Box.createHo
24、riz on talBox(;box2.add(new JLabel(姓名:,JLabel.CENTER;box2.add(姓名;Box box3=Box.createHoriz on talBox(;box3.add(new JLabel(性别:,JLabel.CENTER;box3.add(男;box3.add(女;:,JLabel.CENTER;Box box4=Box.createHoriz on talBox(;box4.add(new JLabel(部门:,JLabel.CENTER;box4.add(部门;Box box6=Box.createHoriz on talBox(;b
25、ox6.add(new JLabel( ”,JLabel.CENTER;Box box5=Box.createHoriz on talBox(;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.createVerticalGlue(;JPa nel pCe nter=new JPa nel(
26、;pCe nter.add(boxH;pCe nter.setBackgro un d(Color.yellow;setLayout (new BorderLayout(;add(pCe nter,BorderLayout.CENTER;JPa nel pSouth=new JPa nel(;pSouth.add(录入修改;pSouth.add(重置;pSouth.setBackgro un d(Color.yellow;add(pSouth,BorderLayout.SOUTH;validate(;public void acti on Performed(Act ion Eve nt ei
27、f(e.getSource(=开始修改 |e.getSource(=职工号String nu mber=;number=职工号.getText(;if(nu mber.le ngth(0try inOne=new FileInputStream(file;in Two=new ObjectI nputStream(i nOne;基本信息表=(Hashtablei nTwo.readObject(;inOn e.close(;in Two.close(;catch(Excepti on eeif(基本信息表.containsKey(number录入修改.setEnabled(true;Emplo
28、yee stu=(Employee 基本信息表.get(number;姓名.setText(stu.getName(;部门.getSelectedltem(;工资.setText(stu.getGrade(;if(stu.getSex(.equals(男.setSelected(true;else女.setSelected(true;else录入修改.setEnabled(false;String warning=该职工号不存在!;JOptio nPan e.showMessageDialog(this,warni ng, 职工号.setText(null;姓名.setText(null;部门
29、.remove(部门.getSelectedltem(;工资.setText(null;else录入修改.setEnabled(false;Stri ng warni ng=必须要输入职工号!;JOptio nPan e.showMessageDialog(this,warni ng, 职工号.setText(null;警告,JOptionPane.WARNING_MESSAGE;警告,JOptionPane.WARNING_MESSAGE;姓名.setText(null;部门.remove(部门.getSelectedltem(;工资.setText(null;else if(e.getSo
30、urce(=录入修改String nu mber=;number=职工号.getText(;if(nu mber.le ngth(0try inOne=new FilelnputStream(file;in Two=new ObjectI nputStream(i nOne;基本信息表=(Hashtablei nTwo.readObject(;inOn e.close(;in Two.close(; catch(Excepti on ee if(基本信息表.containsKey(numberString question=该职工基本信息已存在,您想修改他(她的基本信息吗?;JOpti onP
31、an e.showMessageDialog(this,question, 警告,JOptionPane.QUESTION_MESSAGE;String m=基本信息将被修改!;int ok=JOptio nPan e.showC on firmDialog(this,m,JOptio nPan e.INFORMATION_MESSAGE;if(ok=JOptio nPan e.YES_OPTION确认,JOptionPane.YES_NO_OPTION,String name=姓名.getText(;String discipling=咅部门.getSelectedltem(;String
32、grade= 工资.getText(;String sex=n ull;if(男.isSelected(sex=男.getText(;elsesex=女.getText(;Employee 职工=new Employee(;职工.setNumber(number;职工.setName(name;职工.setDiscipling(discipling;职工.setGrade(grade;职工.setSex(sex;tryout One=new FileOutputStream(file;outTwo=new ObjectOutputStream(out One; 基本信息表.put(number
33、,职工;outTwo.writeObject(基本信息表;outTwo.close(;out On e.close(;职工号.setText(null;姓名.setText(null;部门.remove(部门.getSelectedltem(;工资.setText(null;catch(Excepti on eeSystem.out.pri ntln( ee;录入修改.setEnabled(false;else if(ok=JOptio nPa ne.NO_OPTION录入修改.setEnabled(true;else String warning=该职工号没有基本信息,不能修改!;JOpti
34、o nPan e.showMessageDialog(this,warni ng, 录入修改.setEnabled(false;elseStri ng warni ng=必须要输入职工号!;JOptio nPan e.showMessageDialog(this,warni ng, 录入警告,JOptionPane.WARNING_MESSAGE;警告,JOptionPane.WARNING_MESSAGE;修改.setEnabled(false;if(e.getSource(= 重置职工号.setText(null;姓名.setText(null;部门.remove(部门.getSelect
35、edItem(;工资.setText(null;5、实现职工信息的查询:import java.awt.*;import 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 nerHashtable 基本信息表=n ull;JTextField 职工号,姓名,部门,工资;JRadioButton 男,女;JButton 查询;Butt on Group group=n
36、 ull;File In putStream inOne=n ull;ObjectI nputStream in Two=n ull;File file=null;public Inq uestJFrame f,File filesuper(f,查询对话框,false;this.file=file;职工号=new JTextField(10;查询=new JButton(” 查询;职工号.addActionListener(this;查询.addActionListener(this;姓名=new JTextField(10;姓名.setEditable(false;部门=n ew JText
37、Field(10;部门.setEditable(false;工资=new JTextField(10;工资.setEditable(false;男= =门门 ew JRadioButton(” 男,false;女= =门门 ew JRadioButto n(”女,false;group=new Butt on Group(;group.add(男;group.add(女;Box box 仁仁 Box.createHoriz on talBox(;box1.add( new JLabel(输入要查询的职工号:,JLabel.CENTER;box1.add(职工号;box1.add(查询;Box
38、box2=Box.createHoriz on talBox(;box2.add(new JLabel(姓名:,JLabel.CENTER;box2.add(姓名;Box box3=Box.createHoriz on talBox(;box3.add(new JLabel(性别:,JLabel.CENTER;box3.add(男;box3.add(女;Box box4=Box.createHoriz on talBox(;box4.add(new JLabel(部门:,JLabel.CENTER;box4.add(部门;Box box5=Box.createHoriz on talBox(;
39、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(;JPa nel pCe nter=new JPa nel(;pCe nter.add(boxH;pCe nter.setBackgro un d(Color.gree n;Container con=getC onten tPa
40、ne(;con .add(pCe nter,BorderLayout.CENTER;con. validate(;setVisible(false;setBou nds(100,200,360,270;addWi ndowListe ner(new Win dowAdapter(public void wi ndowClos in g(Wi ndowEve nt e setVisible(false; ;public void acti on Performed(Act ion Eve nt e姓名.setText(null;部门.setText(null;工资.setText(null;if
41、(e.getSource(= 查询 |e.getSource(=String nu mber=;number=职工号.getText(;if(nu mber.le ngth(0try inOne=new FileInputStream(file;in Two=new ObjectI nputStream(i nOne;基本信息表=(Hashtablei nTwo.readObject(;inOn e.close(;in Two.close(;catch(Excepti on eeif(基本信息表.containsKey(number职工号Employee stu=(Employee基本信息表.
42、get(number;姓名.setText(stu.getName(;部门.setText(stu.getDisciping(;工资.setText(stu.getGrade(;if(stu.getSex(.equals(”男”男.setSelected(true;else 女.setSelected(true; elseString warning=该职工号不存在!;JOptio nPan e.showMessageDialog(this,warni ng,elseStri ng warni ng=必须要输入职工号!;JOptio nPan e.showMessageDialog(this,
43、warni ng,6、实现职工信息的删除: import java.awt.*;import java.awt.eve nt.*;import javax.swi ng.*;警告 ”,JOptionPane.WARNING_MESSAGE;警告,JOptionPane.WARNING_MESSAGE;import java.io.*;import java.util.*;public class Delete exte nds JPa nel impleme nts Actio nListe nerHashtable 基本信息表=n ull;JTextField 职工号,姓名,部门,工资;JR
44、adioButton 男,女;JButt on 删除;Butt on Group group=n ull;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 Delete(File filethis.file=file;职工号=new JTextField(10;删除=new JButton(” 删除;职工号.addActionListener(this
45、;删除.addActionListener(this;姓名=new JTextField(10;姓名.setEditable(false;部门=n ew JTextField(10;部门.setEditable(false;工资=new JTextField(10;工资.setEditable(false;男= =门门 ew JRadioButton(” 男,false;女= =门门 ew JRadioButto n(”女,false;group=new Butt on Group(;group.add(男;group.add(女;Box box 仁仁 Box.createHoriz on t
46、alBox(;box1.add( new JLabel(输入要删除的职工:,JLabel.CENTER;box1.add(职工号;box1.add(删除;Box box2=Box.createHoriz on talBox(;box2.add(new JLabel(姓名:,JLabel.CENTER;box2.add(姓名;Box box3=Box.createHoriz on talBox(;box3.add(new JLabel(性别:,JLabel.CENTER;box3.add(男;box3.add(女;Box box4=Box.createHoriz on talBox(;box4.add(new JLabel(部门:,JLabel.CENTER;box4.add(部门;Box box6=Box.createHoriz on talBox(;box6.add(new JLabel( ,JLabel.CENTER;Box box5=Box.createHoriz on talBox(;box5.add(new JLabel(工资:,JLabel.CEN
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 科技驱动的金融产品创新模式研究
- 二零二五年度企业内部控制评估与优化合同
- 2025年度单位与职工解除劳动合同及离职后保密协议
- 二零二五年度水面养殖产业扶贫合作合同
- 二零二五年度电影电视剧演员合同签订与执行协议
- 小学劳动教育与节日文化的融合实践
- 小学科学课程的创新设计与实施策略
- 二零二五年度美容院美容师健康管理与保险劳务合同范本
- 二零二五年度消防器材研发与技术创新基金投资合同
- 2025年度二零二五年度道路工程竣工验收合同简版
- 2025年中国南方航空股份有限公司招聘笔试参考题库含答案解析
- 商务部发布《中国再生资源回收行业发展报告(2024)》
- 山东省济南市2024-2024学年高三上学期1月期末考试 地理 含答案
- 2025年福建新华发行(集团)限责任公司校园招聘高频重点提升(共500题)附带答案详解
- 江苏省驾校考试科目一考试题库
- 四川省成都市青羊区成都市石室联合中学2023-2024学年七上期末数学试题(解析版)
- 咨询公司绩效工资分配实施方案
- 2025新人教版英语七年级下单词表
- 中华护理学会团体标准-气管切开非机械通气患者气道护理
- 未成年入职免责协议书
- 光伏电站巡检专项方案
评论
0/150
提交评论