

下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、java6_職信息管理系統代碼(精)職信息管理系統代碼(精)1、定義職類:public class Employee implements java.io.SerializableString number,name,discipling,grade,borth,sex;publicEmployee(public void setNumber(String numberthis.number=number;public String getNumber(return number;public voidsetName(String =name;public Strin
2、g getName(return name;public void setDiscipling(Stringdisciplingthis.discipling=discipling;public String getDisciping(return discipling;public void setGrade(Stringgradethis.grade=grade;public String getGrade(return grade;public void setBorth(String borththis.borth=borth;public StringgetBorth(return
3、borth;public void setSex(String sexthis.sex=sex;public String getSex(return sex;2、主程序:importjava.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.Hashtable;public classEmployeeManager extends JFrame implements ActionListenerEmployeeSituation 基本信息錄=null;ModifySitua
4、tion 基本信息修改=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;publicEmployeeManager(錄=new JMenuItem(錄職基本信息;修改=new JMenuItem(修改職基本信息;查詢=new JMenu
5、Item(查詢職基本信息;刪除=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.setForeground(Colo
6、r.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(tryFileOutput
7、Stream out=newFileOutputStream(file;ObjectOutputStream objectOut=new ObjectOutputStream(out;objectOut.writeObject(基本信息;objectOut.close(;out.close(;catch(IOException e 基本信息錄=new EmployeeSituation(file;基本信息修改=newModifySituation(file;基本信息查詢=new Inquest(this,file;基本信息刪除=new Delete(file;pCenter.add(歡迎語界,
8、label;pCenter.add(錄界,基本信息錄;pCenter.add(修改界,基本信息修改;pCenter.add(刪除界,基本信息刪除;con.add(pCenter,BorderLayout.CENTER;con.validate(;addWindowListener(new WindowAdapter( public voidwindowClosing(WindowEvent eSystem.exit(0;setVisible(true;setBounds(100,50,420,380;validate(;public voidactionPerformed(ActionEven
9、t 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,刪除界;publicstatic void main(String argsnew EmployeeManager(;3、實現職信息的錄:import java.awt.*;import java.awt.event.*;importjavax.swin
10、g.*;import java.io.*;import java.util.*;public class EmployeeSituation extends JPanel implements ActionListenerHashtable 基本信息表=null;JTextField 職號,姓名,資;Choice 部門;JRadioButton 男,;Employee 職=null;ButtonGroupgroup=null;JButton 錄,重置;FileInputStream inOne=null;ObjectInputStream inTwo=null;FileOutputStream
11、outOne=null;ObjectOutputStream outTwo=null;File file=null; public EmployeeSituation(File file this.file=file;職號=newJTextField(10;姓名=new JTextField(10;部門=new Choice(;部門.add(請選擇;部門.add(研發部;部門.add(銷售部;部門.add(事部;部門.add(安全部;資=new JTextField(10;group=new ButtonGroup(;男=new JRadioButton(男,true;=newJRadioBu
12、tton(,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(姓名:,JLabel.CENTER;box2.add(姓名;Boxbox3=Bo
13、x.createHorizontalBox(; box3.add(new JLabel(性別:,JLabel.CENTER;box3.add(男;box3.add(;Boxbox4=Box.createHorizontalBox(; box4.add(new JLabel(部門:,JLabel.CENTER;box4.add(部門;Boxbox6=Box.createHorizontalBox(;box6.add(new JLabel( ,JLabel.CENTER;Box box5=Box.createHorizontalBox(; box5.add(newJLabel(資:,JLabel.
14、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(Color.yellow;setLayout(newBorderLayout(;add(pCenter,BorderLayout.CE
15、NTER;JPanel pSouth=new JPanel(;pSouth.add(錄;pSouth.add(重置;pSouth.setBackground(Color.yellow;add(pSouth,BorderLayout.SOUTH;validate(;public void actionPerformed(ActionEventeif(e.getSource(=錄String number=;number=職號.getText(;if(number.length(0try inOne=newFileInputStream(file;inTwo=new ObjectInputStre
16、am(inOne;基本信息表=(HashtableinTwo.readObject(;inOne.close(;inTwo.close(;catch(Exception eeif(基本信息表.containsKey(number String warning=該職基本信息已存在,請到修改頁修改!;JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE;else String m=基本信息將被錄!;int ok=JOptionPane.showConfirmDialog(this,m,確認,JOption
17、Pane.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(;職=new Employee(;職.setNumber(number;職.setName(name;職.setDiscipling(disc
18、ipling;職.setGrade(grade;職.setSex(sex;tryoutOne=new FileOutputStream(file;outTwo=new.setDiscipling(discipling;職.setGrade(grade;職.setSex(sex;tryoutOne=new FileOutputStream(file;outTwo=newObjectOutputStream(outOne;基本信息表.put(number,職;outTwo.writeObject(基本信息表;outTwo.close(;outOne.close(;職號.setText(null;姓
19、名.setText(null; 資.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、實現職信息的修改:importjava.awt.*;
20、import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class ModifySituation extendsJPanel implements ActionListener Hashtable 基本信息表=null;JTextField 職號,姓名,資;Choice 部門;JRadioButton 男,;ButtonGroup group=null;JButton 開始修改,錄修改,重置;FileInputStream inOne=null;ObjectInputStr
21、eaminTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File file=null; public ModifySituation(Filefilethis.file=file;職號=new JTextField(10;姓名=new JTextField(10; 部門=new Choice(;部門.add(請選擇;部門.add(研發部;部門.add(銷售部;部門.add(事部;部門.add(安全部;資=new JTextField(10;group=new ButtonGroup(;男=new JRa
22、dioButton(男,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(; box1.add(new
23、 JLabel(輸要修改信息的職號:,JLabel.CENTER;box1.add(職號;box1.add(開始修改;Box box2=Box.createHorizontalBox(; box2.add(newJLabel(姓名:,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(部門:,JLab
24、el.CENTER;box4.add(部門;Box box6=Box.createHorizontalBox(; box6.add(new JLabel( ,JLabel.CENTER;Boxbox5=Box.createHorizontalBox(; box5.add(new JLabel(資:,JLabel.CENTER;box5.add(資;BoxboxH=Box.createVerticalBox(;boxH.add(box1;boxH.add(box2;boxH.add(box3;boxH.add(box5;boxH.add(box6;boxH.add(box4;boxH.add(B
25、ox.createVerticalGlue(;JPanel pCenter=new JPanel(;pCenter.add(boxH;pCenter.setBackground(Color.yellow;setLayout(newBorderLayout(;add(pCenter,BorderLayout.CENTER;JPanel pSouth=new JPanel(;pSouth.add(錄修改;pSouth.add(重置;pSouth.setBackground(Color.yellow;add(pSouth,BorderLayout.SOUTH;validate(;public voi
26、d actionPerformed(ActionEvente if(e.getSource(=開始修改|e.getSource(=職號String number=;number=職號.getText(;if(number.length(0try inOne=newFileInputStream(file;inTwo=new ObjectInputStream(inOne;基本信息表=(HashtableinTwo.readObject(;inOne.close(;inTwo.close(;catch(Exception eeif(基本信息表.containsKey(number 錄修改.set
27、Enabled(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,warning,警告,JOptionPane.WARNING_
28、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(部門.getSelectedItem(;資.setText(null; else if(e.g
29、etSource(=錄修改 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 Stringquestion=該職基本信息已存在,您想修改他(她的基本信息嗎?;JOptionPane.showMe
30、ssageDialog(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=部門.getSelectedItem(;String grade=資.getText(;Stri
31、ng 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=newObjectOutputStream(outOne;基本信息表.put(number,職;outTwo.writeObject(基本信息表;outTwo.
32、close(;outOne.close(;職號.setText(null;姓名.setText(null; 部門.remove(部門.getSelectedItem(;資.setText(null;catch(Exception eeSystem.out.println(ee;錄修改.setEnabled(false; else if(ok=JOptionPane.NO_OPTION錄修改.setEnabled(true;elseStringwarning=該職號沒有基本信息,不能修改!;JOptionPane.showMessageDialog(this,warning,警告,JOption
33、Pane.WARNING_MESSAGE;錄修改.setEnabled(false; elseString warning=必須要輸職號!;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 jav
34、a.awt.event.*;import javax.swing.*;import java.io.*;importjava.util.*;public class Inquest extends JDialog implements ActionListener Hashtable 基本信息表=null;JTextField 職號,姓名,部門,資;JRadioButton 男,;JButton 查詢;ButtonGroup group=null;FileInputStream inOne=null;ObjectInputStreaminTwo=null;File file=null; pub
35、lic 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;部門.setEditable(false;資=new JTextField(10;資.setEditable(false;男=new JRadioButton(
36、男,false;=new JRadioButton(,false;group=new ButtonGroup(;group.add(男;group.add(;Box box1=Box.createHorizontalBox(;=new JRadioButton(,false;group=new ButtonGroup(;group.add(男;group.add(;Box box1=Box.createHorizontalBox(;box1.add(new JLabel(輸要查詢的職號:,JLabel.CENTER;box1.add(職號;box1.add(查詢;Boxbox2=Box.cre
37、ateHorizontalBox(; box2.add(new JLabel(姓名:,JLabel.CENTER;box2.add(姓名;Boxbox3=Box.createHorizontalBox(; box3.add(new JLabel(性別:,JLabel.CENTER;box3.add(男;box3.add(;Boxbox4=Box.createHorizontalBox(; box4.add(new JLabel(部門:,JLabel.CENTER;box4.add(部門;Boxbox5=Box.createHorizontalBox(; box5.add(new JLabel(
38、資:,JLabel.CENTER;box5.add(資;BoxboxH=Box.createVerticalBox(;boxH.add(box1;boxH.add(box2;boxH.add(box3;boxH.add(box5;boxH.add(box4;boxH.add(Box.createVerticalGlue(; JPanelpCenter=new JPanel(;pCenter.add(boxH;pCenter.setBackground(Color.green;Containercon=getContentPane(;con.add(pCenter,BorderLayout.CE
39、NTER;con.validate(;setVisible(false;setBounds(100,200,360,270;addWindWindowAdapter(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=職號.getText(;if
40、(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(;資.setText(stu.get
41、Grade(;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、實現職信息的刪除:importjava.aw
42、t.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class Delete extends JPanelimplements ActionListener Hashtable 基本信息表=null;JTextField 職號,姓名,部門,資;JRadioButton 男,;JButton 刪除;ButtonGroup group=null;FileInputStream inOne=null;ObjectInputStream inTwo=null;FileOu
43、tputStreamoutOne=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(false;資=new JTextField(1
44、0;資.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 JLabel(姓名:,JLabel.CENTER;box2.add
45、(姓名;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;Boxbox5=Box.createHorizontalBox(; box5.add(new JLabel(資:,JLa
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 林火監測與防控考核試卷
- 江西省豐城四中2025年高三下第一次模擬考試化學試題含解析
- 天津濱海汽車工程職業學院《電工電子綜合實踐》2023-2024學年第二學期期末試卷
- 銀川能源學院《口腔頜面外科學實驗一》2023-2024學年第二學期期末試卷
- 岳西縣2024-2025學年數學四下期末教學質量檢測模擬試題含解析
- 伊犁職業技術學院《兒童歌曲伴奏與彈唱》2023-2024學年第二學期期末試卷
- 山西經貿職業學院《基礎化學實驗Ⅱ》2023-2024學年第二學期期末試卷
- 寧夏銀川市名校2025年初三數學試題第一次聯合調考3月聯考試題含解析
- 南京航空航天大學金城學院《基因組與蛋白質組學》2023-2024學年第二學期期末試卷
- 西南科技大學《機場工程概論》2023-2024學年第二學期期末試卷
- 三年級語文 寫通知(全國一等獎)
- 2020電網技術改造工程概算定額第五冊調試工程
- 起重機機械金屬結構
- 自然教育課程的追尋與實踐
- 諾如病毒診斷和治療
- 《無人機攝影測量》考試復習題庫(含答案)
- 職業健康與環境保護的重要性
- 前置胎盤的教學查房課件
- 結構主義詩學
- 2022年初中英語新課標解讀課件
- 工程全過程造價咨詢服務方案(技術方案)
評論
0/150
提交評論