版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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(” 菜單選項(xiàng);fileMenu.add(錄入;fileMenu.add(修改;fileMenu.add(查詢;fileMenu.add(刪除;bar.add(fileMe nu;setJMe nuBar(bar;label=new JLabel(歡迎進(jìn)入職工信息管理系統(tǒng)”,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、實(shí)現(xiàn)職工信息的錄入: 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 職工號(hào),姓名,工資;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;職工號(hào)=new JTextField(10;姓名=new JTextField(10;咅部門=new Choi
12、ce(;部門.add(請(qǐng)選擇;部門.add(”研發(fā)部”;部門.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(職工號(hào):,JLabel.CENTER;box1.add(職工號(hào);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=職工號(hào).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=該職工基本信息已存在,請(qǐng)到修改頁面修改!;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;確認(rèn),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(;職工號(hào).setText(null;姓名.setText(null;工資.setText(null;catch(Excepti on eeSystem.out.pri ntln( ee;elseStri ng warni ng=必須要輸入職工號(hào)??;JOptio nPan e.showMessageDialog(this
20、,warni ng,if(e.getSource(= 重置職工號(hào).setText(null;姓名.setText(null;部門.remove(部門.getSelectedIndex(;工資.setText(null; 4、實(shí)現(xiàn)職工信息的修改: 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 職工號(hào),姓名,工資;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;職工號(hào)=new JTextField(10;姓名=new JTextField(10;咅部門=new Choice(;部門.add(請(qǐng)選擇;部門.add(研發(fā)部;部門.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(” 重置;職工號(hào).addActionListener(this;開始修改.addActionListener(this;錄入修改.addActionListener(this;重置.addActionListener(this;Box box 仁仁 Box.createHoriz on talBox(;box1.add( new JLabel(輸入要修改信息的職工號(hào)box1.add(職工號(hào);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(=職工號(hào)String nu mber=;number=職工號(hào).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=該職工號(hào)不存在??;JOptio nPan e.showMessageDialog(this,warni ng, 職工號(hào).setText(null;姓名.setText(null;部門
29、.remove(部門.getSelectedltem(;工資.setText(null;else錄入修改.setEnabled(false;Stri ng warni ng=必須要輸入職工號(hào)??;JOptio nPan e.showMessageDialog(this,warni ng, 職工號(hào).setText(null;警告,JOptionPane.WARNING_MESSAGE;警告,JOptionPane.WARNING_MESSAGE;姓名.setText(null;部門.remove(部門.getSelectedltem(;工資.setText(null;else if(e.getSo
30、urce(=錄入修改String nu mber=;number=職工號(hào).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確認(rèn),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(;職工號(hào).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=該職工號(hào)沒有基本信息,不能修改!;JOpti
34、o nPan e.showMessageDialog(this,warni ng, 錄入修改.setEnabled(false;elseStri ng warni ng=必須要輸入職工號(hào)??;JOptio nPan e.showMessageDialog(this,warni ng, 錄入警告,JOptionPane.WARNING_MESSAGE;警告,JOptionPane.WARNING_MESSAGE;修改.setEnabled(false;if(e.getSource(= 重置職工號(hào).setText(null;姓名.setText(null;部門.remove(部門.getSelect
35、edItem(;工資.setText(null;5、實(shí)現(xiàn)職工信息的查詢: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 職工號(hào),姓名,部門,工資;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,查詢對(duì)話框,false;this.file=file;職工號(hào)=new JTextField(10;查詢=new JButton(” 查詢;職工號(hào).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(輸入要查詢的職工號(hào):,JLabel.CENTER;box1.add(職工號(hào);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=職工號(hào).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職工號(hào)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=該職工號(hào)不存在??;JOptio nPan e.showMessageDialog(this,warni ng,elseStri ng warni ng=必須要輸入職工號(hào)?。籎Optio nPan e.showMessageDialog(this,
43、warni ng,6、實(shí)現(xiàn)職工信息的刪除: 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 職工號(hào),姓名,部門,工資;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;職工號(hào)=new JTextField(10;刪除=new JButton(” 刪除;職工號(hào).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(輸入要?jiǎng)h除的職工:,JLabel.CENTER;box1.add(職工號(hào);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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度個(gè)人信用貸款合同范本針對(duì)等額本金還款方式2篇
- 2025年度個(gè)人信用借款合同風(fēng)險(xiǎn)管理細(xì)則2篇
- 2025年度電子元器件打膠工藝標(biāo)準(zhǔn)合同范本4篇
- 2025年度出租車司機(jī)個(gè)人租賃車輛合同示范文本3篇
- 2025年度木材產(chǎn)品包裝設(shè)計(jì)與制作合同范本4篇
- 二零二五年度棉紗庫存管理與優(yōu)化方案合同范本4篇
- 二零二五年度商業(yè)廣場(chǎng)戶外遮陽窗簾安裝合同4篇
- 2025年度體育設(shè)施場(chǎng)地租賃及賽事組織服務(wù)合同4篇
- 二零二五年度電器產(chǎn)品安全標(biāo)準(zhǔn)制定合同4篇
- 2025年度生態(tài)池塘承包經(jīng)營權(quán)轉(zhuǎn)讓合同4篇
- 廣東省佛山市2025屆高三高中教學(xué)質(zhì)量檢測(cè) (一)化學(xué)試題(含答案)
- 人教版【初中數(shù)學(xué)】知識(shí)點(diǎn)總結(jié)-全面+九年級(jí)上冊(cè)數(shù)學(xué)全冊(cè)教案
- 2024-2025學(xué)年人教版七年級(jí)英語上冊(cè)各單元重點(diǎn)句子
- 2025新人教版英語七年級(jí)下單詞表
- 公司結(jié)算資金管理制度
- 2024年小學(xué)語文教師基本功測(cè)試卷(有答案)
- 未成年入職免責(zé)協(xié)議書
- 項(xiàng)目可行性研究報(bào)告評(píng)估咨詢管理服務(wù)方案1
- 5歲幼兒數(shù)學(xué)練習(xí)題
- 2024年全國體育單招英語考卷和答案
- 食品安全管理制度可打印【7】
評(píng)論
0/150
提交評(píng)論