《职工信息管理系统代码(共31页).doc》由会员分享,可在线阅读,更多相关《职工信息管理系统代码(共31页).doc(31页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
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 namethis.name=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(修改职工基本信息;查询=new JM
5、enuItem(查询职工基本信息;删除=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(new Font(SansSerif,Font.BOLD+Font.ITALIC,25;label.setForegro
6、und(Color.red;基本信息=new Hashtable(;录入.addActionListener(this;修改.addActionListener(this;查询.addActionListener(this;删除.addActionListener(this;card=new CardLayout(;con=getContentPane(;pCenter=new JPanel(;pCenter.setLayout(card; pCenter.setBackground(Color.yellow;file=new File(基本信息.txt;if(!file.exists(try
7、FileOutputStream out=new FileOutputStream(file;ObjectOutputStream objectOut=new ObjectOutputStream(out;objectOut.writeObject(基本信息;objectOut.close(;out.close(;catch(IOException e 基本信息录入=new EmployeeSituation(file;基本信息修改=new ModifySituation(file;基本信息查询=new Inquest(this,file;基本信息删除=new Delete(file;pCen
8、ter.add(欢迎语界面,label;pCenter.add(录入界面,基本信息录入;pCenter.add(修改界面,基本信息修改; pCenter.add(删除界面,基本信息删除;con.add(pCenter,BorderLayout.CENTER;con.validate(;addWindowListener(new WindowAdapter( public void windowClosing(WindowEvent eSystem.exit(0;setVisible(true;setBounds(100,50,420,380;validate(;public void acti
9、onPerformed(ActionEvent 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 main(String argsnew EmployeeManager(;3、实现职工信息的录入:import java.awt.*;import jav
10、a.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class EmployeeSituation extends JPanel implements ActionListener Hashtable 基本信息表=null; JTextField 职工号,姓名,工资; Choice 部门;JRadioButton 男,女;Employee 职工=null;ButtonGroup group=null;JButton 录入,重置;FileInputStream inOne=null;Objec
11、tInputStream inTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File file=null; public EmployeeSituation(File file this.file=file;职工号=new JTextField(10;姓名=new JTextField(10;部门=new Choice(;部门.add(请选择;部门.add(研发部;部门.add(销售部;部门.add(人事部;部门.add(安全部;工资=new JTextField(10;group=new Button
12、Group(;男=new JRadioButton(男,true;女=new JRadioButton(女,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.a
13、dd(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 bo
14、x5=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(;pCenter.add(boxH;pCenter.setBackground(Colo
15、r.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(=录入String number=;number=职工号.getText(;if(number
16、.length(0try inOne=new FileInputStream(file;inTwo=new ObjectInputStream(inOne;基本信息表=(HashtableinTwo.readObject(;inOne.close(;inTwo.close(;catch(Exception eeif(基本信息表.containsKey(number String warning=该职工基本信息已存在,请到修改页面修改!; JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE;else
17、String m=基本信息将被录入!;int ok=JOptionPane.showConfirmDialog(this,m,确认,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=女.getT
18、ext(;职工=new Employee(;职工.setNumber(number;职工.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; 工资
19、.setText(null;catch(Exception ee System.out.println(ee;else String warning=必须要输入职工号!;JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE; if(e.getSource(=重置 职工号.setText(null;姓名.setText(null;部门.remove(部门.getSelectedIndex(;工资.setText(null;4、实现职工信息的修改:import java.awt.*;import java
20、.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class ModifySituation extends JPanel implements ActionListener Hashtable 基本信息表=null; JTextField 职工号,姓名,工资; Choice 部门;JRadioButton 男,女;ButtonGroup group=null;JButton 开始修改,录入修改,重置;FileInputStream inOne=null;ObjectInputStream
21、inTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File file=null; public ModifySituation(File filethis.file=file;职工号=new JTextField(10;姓名=new JTextField(10; 部门=new Choice(;部门.add(请选择;部门.add(研发部;部门.add(销售部;部门.add(人事部;部门.add(安全部;工资=new JTextField(10;group=new ButtonGroup(;男=new JR
22、adioButton(男,true;女=new JRadioButton(女,false;group.add(男;group.add(女;开始修改=new JButton(开始修改;录入修改=new JButton(录入修改;录入修改.setEnabled(false;重置=new JButton(重置;职工号.addActionListener(this;开始修改.addActionListener(this;录入修改.addActionListener(this;重置.addActionListener(this;Box box1=Box.createHorizontalBox(; box
23、1.add(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 J
24、Label(部门:,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.
25、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,BorderLayout.SOUT
26、H;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(;catch(Exception eeif(基本信息表.
27、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=该职工号不存在!;JOptionPane.showMessageDialog(this,
28、warning,警告,JOptionPane.WARNING_MESSAGE;职工号.setText(null;姓名.setText(null; 部门.remove(部门.getSelectedItem(;工资.setText(null;else 录入修改.setEnabled(false; String warning=必须要输入职工号!;JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE;职工号.setText(null;姓名.setText(null; 部门.remove(部门.getSele
29、ctedItem(;工资.setText(null; else if(e.getSource(=录入修改 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 question=该职
30、工基本信息已存在,您想修改他(她的基本信息吗?;JOptionPane.showMessageDialog(this,question,警告,JOptionPane.QUESTION_MESSAGE;String m=基本信息将被修改!;int ok=JOptionPane.showConfirmDialog(this,m,确认,JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE;if(ok=JOptionPane.YES_OPTIONString name=姓名.getText(;String discipling=部门.get
31、SelectedItem(;String grade=工资.getText(;String sex=null;if(男.isSelected(sex=男.getText(;elsesex=女.getText(;Employee 职工=new Employee(;职工.setNumber(number;职工.setName(name;职工.setDiscipling(discipling;职工.setGrade(grade;职工.setSex(sex;tryoutOne=new FileOutputStream(file;outTwo=new ObjectOutputStream(outOne;
32、基本信息表.put(number,职工;outTwo.writeObject(基本信息表;outTwo.close(;outOne.close(;职工号.setText(null;姓名.setText(null; 部门.remove(部门.getSelectedItem(;工资.setText(null;catch(Exception ee System.out.println(ee;录入修改.setEnabled(false; else if(ok=JOptionPane.NO_OPTION录入修改.setEnabled(true;elseString warning=该职工号没有基本信息,
33、不能修改!;JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE;录入修改.setEnabled(false; elseString warning=必须要输入职工号!;JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE;录入修改.setEnabled(false;if(e.getSource(=重置 职工号.setText(null;姓名.setText(null;部门.remove(部门.getSele
34、ctedItem(;工资.setText(null;5、实现职工信息的查询:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class Inquest extends JDialog implements ActionListener Hashtable 基本信息表=null; JTextField 职工号,姓名,部门,工资; JRadioButton 男,女;JButton 查询;ButtonGroup group=null;Fi
35、leInputStream inOne=null;ObjectInputStream inTwo=null;File file=null; public Inquest(JFrame f,File filesuper(f,查询对话框,false; this.file=file;职工号=new JTextField(10;查询=new JButton(查询;职工号.addActionListener(this;查询.addActionListener(this;姓名=new JTextField(10;姓名.setEditable(false;部门=new JTextField(10;部门.se
36、tEditable(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(new JLabel(输入要查询的职工号:,JLabel.CENTER;box1.add(职工号;box1.add(查询;Box box2=Box.createHorizontalBox(; b
37、ox2.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 box5=Box.createHorizontalBox(; box5.add(new JLabel(工资:,JLabel.CENTE
38、R;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.v
39、alidate(;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=;number=职工号.get
40、Text(;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.getDisciping(;工资.setTex
41、t(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.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE;6、实现职工信息的删除
42、: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 男,女;JButton 删除;ButtonGroup group=null;FileInputStream inOne=null;ObjectInputStr
43、eam 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(this;姓名=new JTextField(10;姓名.setEditable(false;部门=new JTextField(10;部门.setEditable(
44、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(new JLabel(输入要删除的职工:,JLabel.CENTER;box1.add(职工号;box1.add(删除;Box box2=Box.createHorizontalBox(; box2.add(new