版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上1、定义职工类:public class Employee implements java.io.SerializableString number,name,discipling,grade,borth,sex;public Employee(public void setNumber(String numberthis.number=number;public String getNumber(return number;public void setName(String =name;public String getName(retu
2、rn name;public void setDiscipling(String disciplingthis.discipling=discipling;public String getDisciping(return discipling;public void setGrade(String gradethis.grade=grade;public String getGrade(return grade;public void setBorth(String borththis.borth=borth;public String getBorth(return borth;publi
3、c void setSex(String sexthis.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 ActionListenerEmployeeSituation 基本信息录入=null; ModifySituation 基本
4、信息修改=null; Inquest 基本信息查询=null; Delete 基本信息删除=null; JMenuBar bar; 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("修
5、改职工基本信息"查询=new JMenuItem("查询职工基本信息"删除=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.s
6、etFont(new Font("SansSerif",Font.BOLD+Font.ITALIC,25;label.setForeground(Color.red;基本信息=new Hashtable(;录入.addActionListener(this;修改.addActionListener(this;查询.addActionListener(this;删除.addActionListener(this;card=new CardLayout(;con=getContentPane(;pCenter=new JPanel(;pCenter.setLayout(card
7、; pCenter.setBackground(Color.yellow;file=new File("基本信息.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(fil
8、e;基本信息修改=new ModifySituation(file;基本信息查询=new Inquest(this,file;基本信息删除=new Delete(file;pCenter.add("欢迎语界面",label;pCenter.add("录入界面",基本信息录入;pCenter.add("修改界面",基本信息修改; pCenter.add("删除界面",基本信息删除;con.add(pCenter,BorderLayout.CENTER;con.validate(;addWindowListener(n
9、ew WindowAdapter( public void windowClosing(WindowEvent eSystem.exit(0;setVisible(true;setBounds(100,50,420,380;validate(;public void actionPerformed(ActionEvent eif(e.getSource(=录入card.show(pCenter,"录入界面"else if(e.getSource(=修改card.show(pCenter,"修改界面"else if(e.getSource(=查询基本信息查
10、询.setVisible(true;else if(e.getSource(=删除card.show(pCenter,"删除界面"public static void main(String argsnew EmployeeManager(;3、实现职工信息的录入:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class EmployeeSituation extends JPanel implements A
11、ctionListener Hashtable 基本信息表=null; JTextField 职工号,姓名,工资; Choice 部门;JRadioButton 男,女;Employee 职工=null;ButtonGroup group=null;JButton 录入,重置;FileInputStream inOne=null;ObjectInputStream inTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File file=null; public EmployeeSituation(File
12、 file this.file=file;职工号=new JTextField(10;姓名=new JTextField(10;部门=new Choice(;部门.add("请选择"部门.add("研发部"部门.add("销售部"部门.add("人事部"部门.add("安全部"工资=new JTextField(10;group=new ButtonGroup(;男=new JRadioButton("男",true;女=new JRadioButton("女&qu
13、ot;,false;group.add(男;group.add(女;录入=new JButton("录入"重置=new JButton("重置"录入.addActionListener(this;重置.addActionListener(this;Box box1=Box.createHorizontalBox(; box1.add(new JLabel("职工号:",JLabel.CENTER;box1.add(职工号;Box box2=Box.createHorizontalBox(; box2.add(new JLabel(&q
14、uot;姓名:",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(部门;Box box6=Box.createHorizontalBox(;box6.add(new JLabel(&q
15、uot; ",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.createVerticalGlue(; JPanel pCenter=new JPanel(
16、;pCenter.add(boxH;pCenter.setBackground(Color.yellow;setLayout(new BorderLayout(;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 eif(e.getSource(=录入
17、String number=""number=职工号.getText(;if(number.length(>0try inOne=new FileInputStream(file;inTwo=new ObjectInputStream(inOne;基本信息表=(HashtableinTwo.readObject(;inOne.close(;inTwo.close(;catch(Exception eeif(基本信息表.containsKey(number String warning="该职工基本信息已存在,请到修改页面修改!" JOptionPa
18、ne.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE;else String m="基本信息将被录入!"int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE;if(ok=JOptionPane.YES_OPTIONString name=姓名.getText(;String discipling=部
19、门.getSelectedItem(;String grade=工资.getText(;String sex=null;if(男.isSelected(sex=男.getText(;elsesex=女.getText(;职工=new Employee(;职工.setNumber(number;职工.setName(name;职工.setDiscipling(discipling;职工.setGrade(grade;职工.setSex(sex;tryoutOne=new FileOutputStream(file;outTwo=new ObjectOutputStream(outOne;基本信息
20、表.put(number,职工;outTwo.writeObject(基本信息表;outTwo.close(;outOne.close(;职工号.setText(null;姓名.setText(null; 工资.setText(null;catch(Exception ee System.out.println(ee;else String warning="必须要输入职工号!"JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE; if(e.getSour
21、ce(=重置 职工号.setText(null;姓名.setText(null;部门.remove(部门.getSelectedIndex(;工资.setText(null;4、实现职工信息的修改:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class ModifySituation extends JPanel implements ActionListener Hashtable 基本信息表=null; JTextField
22、 职工号,姓名,工资; Choice 部门;JRadioButton 男,女;ButtonGroup group=null;JButton 开始修改,录入修改,重置;FileInputStream inOne=null;ObjectInputStream inTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File file=null; public ModifySituation(File filethis.file=file;职工号=new JTextField(10;姓名=new JTextFiel
23、d(10; 部门=new Choice(;部门.add("请选择"部门.add("研发部"部门.add("销售部"部门.add("人事部"部门.add("安全部"工资=new JTextField(10;group=new ButtonGroup(;男=new JRadioButton("男",true;女=new JRadioButton("女",false;group.add(男;group.add(女;开始修改=new JButton("开
24、始修改"录入修改=new JButton("录入修改"录入修改.setEnabled(false;重置=new JButton("重置"职工号.addActionListener(this;开始修改.addActionListener(this;录入修改.addActionListener(this;重置.addActionListener(this;Box box1=Box.createHorizontalBox(; box1.add(new JLabel("输入要修改信息的职工号:",JLabel.CENTER;box1
25、.add(职工号;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("部门:",JL
26、abel.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.ad
27、d(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.CENTER;JPanel pSouth=new JPanel(;pSouth.add(录入修改;pSouth.add(重置;pSouth.setBackground(Color.yellow;add(pSouth,Borde
28、rLayout.SOUTH;validate(;public void actionPerformed(ActionEvent e if(e.getSource(=开始修改|e.getSource(=职工号String number=""number=职工号.getText(;if(number.length(>0try inOne=new FileInputStream(file;inTwo=new ObjectInputStream(inOne;基本信息表=(HashtableinTwo.readObject(;inOne.close(;inTwo.close(;
29、catch(Exception eeif(基本信息表.containsKey(number 录入修改.setEnabled(true;Employee stu=(Employee基本信息表.get(number;姓名.setText(stu.getName(;部门.getSelectedItem(;工资.setText(stu.getGrade(;if(stu.getSex(.equals("男"男.setSelected(true;else女.setSelected(true; else 录入修改.setEnabled(false;String warning="
30、;该职工号不存在!"JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE;职工号.setText(null;姓名.setText(null; 部门.remove(部门.getSelectedItem(;工资.setText(null;else 录入修改.setEnabled(false; String warning="必须要输入职工号!"JOptionPane.showMessageDialog(this,warning,"警告&quo
31、t;,JOptionPane.WARNING_MESSAGE;职工号.setText(null;姓名.setText(null; 部门.remove(部门.getSelectedItem(;工资.setText(null; else if(e.getSource(=录入修改 String number=""number=职工号.getText(;if(number.length(>0try inOne=new FileInputStream(file;inTwo=new ObjectInputStream(inOne;基本信息表=(HashtableinTwo.rea
32、dObject(;inOne.close(;inTwo.close(; catch(Exception eeif(基本信息表.containsKey(number String question="该职工基本信息已存在,您想修改他(她的基本信息吗?"JOptionPane.showMessageDialog(this,question,"警告",JOptionPane.QUESTION_MESSAGE;String m="基本信息将被修改!"int ok=JOptionPane.showConfirmDialog(this,m,&qu
33、ot;确认",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE;if(ok=JOptionPane.YES_OPTIONString name=姓名.getText(;String discipling=部门.getSelectedItem(;String grade=工资.getText(;String sex=null;if(男.isSelected(sex=男.getText(;elsesex=女.getText(;Employee 职工=new Employee(;职工.setNumber(number;职工.
34、setName(name;职工.setDiscipling(discipling;职工.setGrade(grade;职工.setSex(sex;tryoutOne=new FileOutputStream(file;outTwo=new ObjectOutputStream(outOne;基本信息表.put(number,职工;outTwo.writeObject(基本信息表;outTwo.close(;outOne.close(;职工号.setText(null;姓名.setText(null; 部门.remove(部门.getSelectedItem(;工资.setText(null;c
35、atch(Exception ee System.out.println(ee;录入修改.setEnabled(false; else if(ok=JOptionPane.NO_OPTION录入修改.setEnabled(true;elseString warning="该职工号没有基本信息,不能修改!"JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE;录入修改.setEnabled(false; elseString warning="必须要
36、输入职工号!"JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE;录入修改.setEnabled(false;if(e.getSource(=重置 职工号.setText(null;姓名.setText(null;部门.remove(部门.getSelectedItem(;工资.setText(null;5、实现职工信息的查询:import java.awt.*;import java.awt.event.*;import javax.swing.*;import
37、java.io.*;import java.util.*;public class Inquest extends JDialog implements ActionListener Hashtable 基本信息表=null; JTextField 职工号,姓名,部门,工资; JRadioButton 男,女;JButton 查询;ButtonGroup group=null;FileInputStream inOne=null;ObjectInputStream inTwo=null;File file=null; public Inquest(JFrame f,File filesuper
38、(f,"查询对话框",false; this.file=file;职工号=new JTextField(10;查询=new JButton("查询"职工号.addActionListener(this;查询.addActionListener(this;姓名=new JTextField(10;姓名.setEditable(false;部门=new JTextField(10;部门.setEditable(false;工资=new JTextField(10;工资.setEditable(false;男=new JRadioButton("男&
39、quot;,false;女=new JRadioButton("女",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;
40、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(部门;Box box5=Box.createHorizontalBox(; box5.add(new JLabel("工资:",JLabel.CENTER
41、;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.setBackground(Color.green;Container con=getContentPane(;con.add(pCenter,BorderLayout.CENTER;con.va
42、lidate(;setVisible(false;setBounds(100,200,360,270;addWindowListener(new WindowAdapter(public void windowClosing(WindowEvent esetVisible(false; ;public void actionPerformed(ActionEvent e 姓名.setText(null;部门.setText(null;工资.setText(null;if(e.getSource(=查询|e.getSource(=职工号String number=""numb
43、er=职工号.getText(;if(number.length(>0try inOne=new FileInputStream(file;inTwo=new ObjectInputStream(inOne;基本信息表=(HashtableinTwo.readObject(;inOne.close(;inTwo.close(;catch(Exception eeif(基本信息表.containsKey(number Employee stu=(Employee基本信息表.get(number;姓名.setText(stu.getName(;部门.setText(stu.getDiscip
44、ing(;工资.setText(stu.getGrade(;if(stu.getSex(.equals("男"男.setSelected(true;else女.setSelected(true; else String warning="该职工号不存在!"JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE;else String warning="必须要输入职工号!"JOptionPane.showMessageDi
45、alog(this,warning,"警告",JOptionPane.WARNING_MESSAGE;6、实现职工信息的删除:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class Delete extends JPanel implements ActionListener Hashtable 基本信息表=null; JTextField 职工号,姓名,部门,工资; JRadioButton 男,女;JBu
46、tton 删除;ButtonGroup group=null;FileInputStream inOne=null;ObjectInputStream inTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File file=null; public Delete(File filethis.file=file;职工号=new JTextField(10;删除=new JButton("删除"职工号.addActionListener(this;删除.addActionListener(
47、this;姓名=new JTextField(10;姓名.setEditable(false;部门=new JTextField(10;部门.setEditable(false;工资=new JTextField(10;工资.setEditable(false;男=new JRadioButton("男",false;女=new JRadioButton("女",false;group=new ButtonGroup(;group.add(男;group.add(女;Box box1=Box.createHorizontalBox(; box1.add(
48、new JLabel("输入要删除的职工:",JLabel.CENTER;box1.add(职工号;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(部门;Box box6=Box.createHorizontalBox(; box6.add(new JLabel(" ",JLabel.CENTER;Box box5=Box.createHorizontalBox(; box5.add(new JLabel("工资:",JLabe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度坡屋面小青瓦施工质量监督与整改服务合同
- 二零二五年度新加坡留学就业辅导合同4篇
- 2025专业级防雷系统设计与施工监管合同3篇
- 商场自动扶梯安装与维护服务合同(2025年度)
- 二零二五版罗丝与杨洋的离婚协议及财产分割及子女抚养协议4篇
- 2025年度家具退货及维修保养服务协议范本
- 2025版GB∕T30057(环保)固体废物处理与资源化利用合同3篇
- 二零二五年度历史文化遗址草坪保护与旅游合同3篇
- 二零二五年度医疗信息化系统建设与维护合同2篇
- 2025版新型绿色建筑劳务分包合同范本3篇
- 副总经理招聘面试题与参考回答(某大型国企)2024年
- PDCA循环提高护士培训率
- 2024-2030年中国智慧水务行业应用需求分析发展规划研究报告
- 《狮子王》电影赏析
- 河北省保定市定州市2025届高二数学第一学期期末监测试题含解析
- 中医护理人文
- 2024-2030年中国路亚用品市场销售模式与竞争前景分析报告
- 货物运输安全培训课件
- 前端年终述职报告
- 2024小说推文行业白皮书
- 市人民医院关于开展“改善就医感受提升患者体验主题活动”2023-2025年实施方案及资料汇编
评论
0/150
提交评论