1、 this。name=name; public String getName() return name; public void setDiscipling(String discipling) this.discipling=discipling; public String getDisciping() return discipling; public void setGrade(String grade)grade=grade; public String getGrade() return grade; public void setBorth(String borth) this
2、.borth=borth; public String getBorth() return borth; public void setSex(String sex) this.sex=sex; public String getSex() return sex; 2、主程序:import java。awt。*;event.*;import javax.swing。;import java.io。util。Hashtable;public class EmployeeManager extends JFrame implements ActionListener EmployeeSituati
3、on 基本信息录入=null; ModifySituation 基本信息修改=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(”录入员工
4、基本信息); 修改=new JMenuItem(修改员工基本信息); 查询=new JMenuItem(查询员工基本信息”); 删除=new JMenuItem(”删除员工基本信息 bar=new JMenuBar(); fileMenu=new JMenu(菜单选项”); fileMenu.add(录入); fileMenu。add(修改);add(查询);add(删除); bar。add(fileMenu); setJMenuBar(bar); label=new JLabel(”欢迎进入员工信息管理系统”,JLabel.CENTER); label。setFont(new Font(Sa
5、nsSerif”,Font.BOLD+Font.ITALIC,25);setForeground(Color.red); 基本信息=new Hashtable(); 录入.addActionListener(this); 修改。addActionListener(this); 查询。 删除。addActionListener(this); card=new CardLayout(); con=getContentPane(); pCenter=new JPanel(); pCenter.setLayout(card); pCenter.setBackground(Color.yellow);
6、file=new File(”基本信息.txt”); if(!file.exists() try FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut。writeObject(基本信息); objectOut.close(); out.close(); catch(IOException e) 基本信息录入=new EmployeeSituation(file); 基本信息修改=new ModifySituation
7、(file); 基本信息查询=new Inquest(this,file); 基本信息删除=new Delete(file); pCenter.add(”欢迎语界面,label); pCenter。add(录入界面,基本信息录入); pCenter.add(修改界面”,基本信息修改);删除界面”,基本信息删除); con。add(pCenter,BorderLayout.CENTER);validate(); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0)
8、; ); 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,
9、删除界面 public static void main(String args) new EmployeeManager(); 3、实现员工信息的录入:awt.;awt.event.*;import javax。swing.*;io。;public class EmployeeSituation extends JPanel implements ActionListener Hashtable 基本信息表=null; JTextField 员工号,姓名,工资; Choice 部门; JRadioButton 男,女; Employee 员工=null; ButtonGroup group=
10、null; JButton 录入,重置; FileInputStream inOne=null; ObjectInputStream 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(”请选择 部门。研发部”);销售部人事部
11、 部门.add(”安全部 工资=new JTextField(10); group=new ButtonGroup(); 男=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(
12、”员工号:,JLabel。CENTER); box1.add(员工号); Box box2=Box。createHorizontalBox(); box2.add(new JLabel(姓名:”,JLabel。CENTER); box2。add(姓名); Box box3=Box。 box3。add(new JLabel(性别:,JLabel.CENTER); box3.add(男); box3.add(女); Box box4=Box。 box4.add(new JLabel(”部门: box4。add(部门); Box box6=Box.createHorizontalBox(); box
13、6.add(new JLabel( Box box5=Box.createHorizontalBox(); box5.add(new JLabel(”工资: box5.add(工资); Box boxH=Box。createVerticalBox(); boxH。add(box1); boxH.add(box2);add(box3);add(box5); boxH.add(box6);add(box4); boxH.add(Box.createVerticalGlue(); JPanel pCenter=new JPanel(); pCenter.add(boxH); pCenter。setB
14、ackground(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 e) if(e。getSource()=录入) String
15、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(基本信息表.containsKey(number) String warning=”该员工基本信息已存在,请到修改页面修改! JOptionPane.showMessa
16、geDialog(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_OPTION) String name=姓名。getText(); String discipling=部门.getSelectedItem(); String grade=工资
17、。 String sex=null; if(男。isSelected() sex=男.getText(); sex=女.getText(); 员工=new Employee(); 员工。setNumber(number); 员工.setName(name); 员工.setDiscipling(discipling);setGrade(grade); 员工.setSex(sex); try outOne=new FileOutputStream(file); outTwo=new ObjectOutputStream(outOne); 基本信息表。put(number,员工); outTwo。w
18、riteObject(基本信息表);close(); outOne。close(); 员工号。setText(null); 姓名。setText(null); 工资.setText(null); System。out。println(ee); else String warning=必须要输入员工号!; JOptionPane。showMessageDialog(this,warning,警告”,JOptionPane。 if(e。getSource()=重置) 员工号。 姓名。 部门.remove(部门。getSelectedIndex(); 工资。 4、实现员工信息的修改:import j
19、ava.awt.;import java.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=nul
20、l; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; File file=null; public ModifySituation(File file) this.file=file; 员工号=new JTextField(10); 姓名=new JTextField(10); 部门=new Choice(); 部门.add(”请选择”); 部门.add(”研发部 部门.add(”销售部”); 部门。 部门.add(”安全部”); 工资=new JTextFi
21、eld(10); group=new ButtonGroup(); 男=new JRadioButton(”男”,true); 女=new JRadioButton(”女,false); group.add(男); group.add(女); 开始修改=new JButton(开始修改”); 录入修改=new JButton(录入修改 录入修改。setEnabled(false); 重置=new JButton(”重置 员工号.addActionListener(this); 开始修改。 录入修改.addActionListener(this); 重置.addActionListener(th
22、is); Box box1=Box。 box1.add(new JLabel(输入要修改信息的员工号:”,JLabel。 box1。add(员工号);add(开始修改); Box box2=Box.createHorizontalBox(); box2。 Box box3=Box。 box3。add(new JLabel(”性别:”,JLabel.CENTER); box3.add(男); box3.add(女); Box box4=Box.createHorizontalBox(); box4。部门:,JLabel。 box4.add(部门); Box box6=Box.createHori
23、zontalBox(); box6。 Box box5=Box.createHorizontalBox(); box5.add(new JLabel(”工资: box5.add(工资); Box boxH=Box。 boxH.add(box1); boxH。add(box2);add(box3); boxH.add(box5); boxH.add(box6); boxH.add(box4); boxH.add(Box。createVerticalGlue(); JPanel pCenter=new JPanel(); pCenter.add(boxH);setBackground(Color。yellow); setLayout(new BorderLayout(); add(pCenter,BorderLayout。CENTER); JPanel pSouth=new JPanel(); pSouth。add(录入修改); pSo
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2