1、. ./车辆管理系统package javaapplication27;import javax.swing.*;import java.io.*;import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.filechooser.*;import java.io.FileInputStream;/3.4CarPicture 类class CarPicture extends JPanel File imageFile;Toolkit tool;public CarPicture() tool=
2、getToolkit(); publicvoid setImage(File imageFile) this.imageFile=imageFile; repaint(); Overridepublicvoid paintponent(Graphics g) super.paintponent(g);int w=getBounds().width;int h=getBounds().height;if(imageFile!=null) Image image=tool.getImage(imageFile.getAbsolutePath(); g.drawImage(image, 0,0,w,
3、h, this); /3.3Car类class Car implementsSerializable String number,name,discipling,grade,borth,sex;File imagePic;publicvoid setNumber(String number) this.number=number; publicString getNumber() return number; publicvoid setName(String name) this.name=name; publicString getName() return name; publicvoi
4、d setDiscipling(String discipling) this.discipling=discipling; publicString getDiscipling() return discipling; publicvoid setGrade(String grade) this.grade=grade; publicString getGrade() return grade; publicvoid setBorth(String borth) this.borth=borth; publicString getBorth() return borth; publicvoi
5、d setSex(String sex) this.sex=sex; publicString getSex() return sex; publicvoid setImagePic(File image) imagePic=image; publicFile getImagePic() return imagePic; /3.5InputCar类class InputCar extends JPanel implementsActionListener Car 车主=null; CarPicture pic; HashMap根本信息表=null; JTextField 车牌号,XX,购车公司
6、,购车时间; utton 选择照片; oBox 档次; JRadioButton 男,女;ButtonGroup group=null; utton 录入,重置;FileInputStream inOne=null;ObjectInputStream inTwo=null;FileInputStream outOne=null;ObjectOutputStream outTwo=null;File systemFile,imagePic;public InputCar(File file) systemFile=file; pic=new CarPicture();车牌号=new JTextF
7、ield(5);XX=new JTextField(5);档次=new oBox();try FileReader inOne = newFileReader(专业.txt);BufferedReader inTwo = newBufferedReader(inOne);String s = null;int i=0;while(s=inTwo.readLine()!=null)档次.addItem(s); inOne.close(); inTwo.close(); catch(IOException exp)档次.addItem(高级);档次.addItem(中高级);档次.addItem(
8、中级);档次.addItem(中低级);档次.addItem(普通); 购车公司=new JTextField(5);购车时间=new JTextField(5);选择照片=new utton(选择); group=new ButtonGroup();男=new JRadioButton(男,true);女=new JRadioButton(女,true); group.add(男); group.add(女);录入=new utton(录入);重置=new utton(重置);录入.addActionListener(this);选择照片.addActionListener(this);重置
9、.addActionListener(this); Box box1=Box.createHorizontalBox(); box1.add(new JLabel(车牌号:,JLabel.CENTER); box1.add(车牌号); Box box2=Box.createHorizontalBox(); box2.add(new JLabel(车主XX:,JLabel.CENTER); box2.add(XX); Box box3=Box.createHorizontalBox(); box3.add(new JLabel(车主性别:,JLabel.CENTER); box3.add(男);
10、 box3.add(女); Box box4=Box.createHorizontalBox(); box4.add(new JLabel(车辆档次:,JLabel.CENTER); box4.add(档次); Box box5=Box.createHorizontalBox(); box5.add(new JLabel(购车公司:,JLabel.CENTER); box5.add(购车公司); Box box6=Box.createHorizontalBox(); box6.add(new JLabel(购车时间:,JLabel.CENTER);box6.add(购车时间); Box box
11、H=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(Box.createVerticalGlue(); JPanel picPanel=new JPanel(); picPanel.setBackground(Color.green); picPanel.add(new JLabel(选择照片:,JLabel.CENTER); picPanel.add(选择照片); JPanel pu
12、tButton=new JPanel(); putButton.add(录入); putButton.add(重置); JPanel messPanel=new JPanel(); messPanel.add(boxH); messPanel.setBackground(Color.cyan); putButton.setBackground(Color.red); setLayout(newBorderLayout(); JSplitPane splitV=new JSplitPane(JSplitPane.VERTICAL_SPLIT,picPanel,pic); JSplitPane s
13、plitH=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,messPanel,splitV); add(splitH,BorderLayout.CENTER); add(putButton,BorderLayout.SOUTH); validate(); publicvoid actionPerformed(ActionEvent e)if(e.getSource()=录入)String number=; number=车牌号.getText();if(number.length()0)try inOne =newFileInputStream(syst
14、emFile); inTwo =newObjectInputStream(inOne);根本信息表=(HashMap)inTwo.readObject(); inOne.close(); inTwo.close(); catch(Exception ee)if(根本信息表.containsKey(number)String warning=该生根本信息已存在,请到修改页面修改!; JOptionPane.showMessageDialog(this,warning, 警告,JOptionPane.WARNING_MESSAGE); elseString m=根本信息将被录入!;int ok=J
15、OptionPane.showConfirmDialog(this,m, 确认,JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);if(ok=JOptionPane.YES_OPTION)String name=XX.getText();String discipling=(String)档次.getSelectedItem();String grade=购车公司.getText();String borth=购车时间.getText();String sex=null;if(男.isSelected() sex=男.getT
16、ext();else sex=女.getText();车主=new Car();车主.setNumber(number);车主.setName(name);车主.setDiscipling(discipling);车主.setGrade(grade);车主.setBorth(borth);车主.setSex(sex);车主.setImagePic(imagePic);try FileOutputStream outOne=newFileOutputStream(systemFile); outTwo=newObjectOutputStream(outOne);根本信息表.put(number,
17、车主); outTwo.writeObject(根本信息表); outTwo.close(); outOne.close(); clearMess(); catch(Exception ee) elseString warning=必须要输入学号!; JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE); elseif(e.getSource()=选择照片) JFileChooser chooser=new JFileChooser(); FileNameExtensionFilter filter
18、=new FileNameExtensionFilter(JPG&GIF Images,jpg,gif); chooser.setFileFilter(filter);int state=chooser.showOpenDialog(null);File choiceFile=chooser.getSelectedFile();if(choiceFile!=null&state=JFileChooser.APPROVE_OPTION)选择照片.setText(choiceFile.getName(); imagePic=choiceFile; pic.setImage(imagePic); p
19、ic.repaint(); elseif(e.getSource()=重置) clearMess(); publicvoid clearMess()车牌号.setText(null);XX.setText(null);购车公司.setText(null);购车时间.setText(null);选择照片.setText(选择); imagePic=null; pic.setImage(imagePic); pic.repaint(); /3.6inquset类class Inquest extends JDialog implementsActionListener CarPicture pic
20、;PrintJob print;Graphics g=null; HashMap根本信息表; JTextField 车牌号,XX,档次,购车公司,购车时间; JRadioButton 男,女; utton 查询,打印文本及照片,打印文本,打印照片; ButtonGroup group=null;FileInputStream inOne=null;ObjectInputStream inTwo=null;File systemFile=null; JPanel messPanel; Car stu;public Inquest(File file) setTitle(查询对话框); setMo
21、dal(false); systemFile=file; pic =new CarPicture();车牌号=new JTextField(6);查询=new utton(查询);车牌号.addActionListener(this);查询.addActionListener(this);打印文本及照片=new utton(打印文本及照片);打印文本=new utton(打印文本);打印照片=new utton(打印照片);打印文本及照片.addActionListener(this);打印文本.addActionListener(this);打印照片.addActionListener(th
22、is);打印文本及照片.setEnabled(false);打印文本.setEnabled(false);打印照片.setEnabled(false);XX=new JTextField(5);XX.setEditable(false);档次=new JTextField(5);档次.setEditable(false);购车公司=new JTextField(5);购车公司.setEditable(false);购车时间=new JTextField(5);购车时间.setEditable(false);男=new JRadioButton(男,false);女=new JRadioButt
23、on(女,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(车主XX:,JLabel.CENTER); box2.add(XX); Box box3=Box.createHorizontalBox();
24、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); box5.add(购车公司); Box box6=Box.createHorizontalBox(); box6.add(new J
25、Label(购车时间:,JLabel.CENTER); box6.add(购车时间); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); messPanel=new JPanel(); messPanel.add(boxH); JSplitPane splitH=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,messPanel,pic); add(
26、splitH,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(打印文本及照片); pSouth.add(打印文本); pSouth.add(打印照片); add(pSouth,BorderLayout.SOUTH); validate(); setVisible(false); setSize(360,230); addWindowListener(newWindowAdapter() Overridepublicvoid windowClosing(WindowEvent e) setVisible(false););
27、publicvoid actionPerformed(ActionEvent e)if(e.getSource()=查询|e.getSource()=车牌号)String number=; number=车牌号.getText();if(number.length()0)try inOne=newFileInputStream(systemFile); inTwo=newObjectInputStream(inOne);根本信息表=(HashMap)inTwo.readObject(); inOne.close(); inTwo.close(); catch(Exception ee)if(根
28、本信息表.containsKey(number) stu=根本信息表.get(number);XX.setText(stu.getName();档次.setText(stu.getDiscipling();购车公司.setText(stu.getGrade();购车时间.setText(stu.getBorth();if(stu.getSex().equals(男)男.setSelected(true);else女.setSelected(true); pic.setImage(stu.getImagePic(); pic.repaint();打印文本及照片.setEnabled(true);
29、打印文本.setEnabled(true);打印照片.setEnabled(true); else打印文本及照片.setEnabled(false);打印文本.setEnabled(false);打印照片.setEnabled(false);String warning=该车牌号不存在!; JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE); clearMess(); else打印文本及照片.setEnabled(false);打印文本.setEnabled(false);打印照片.setEnab
30、led(false);String warning=必须要输入车牌号!; JOptionPane.showMessageDialog(this,warning,警告, JOptionPane.WARNING_MESSAGE); elseif(e.getSource()=打印文本及照片)try print=getToolkit().getPrintJob(new JFrame(),打印,newProperties(); g=print.getGraphics(); g.translate(120,200);int w=messPanel.getBounds().width; messPanel.
31、printAll(g); g.translate(w,0); pic.printAll(g);XX.setText(stu.getName(); g.dispose(); print.end(); catch(Exception exp) elseif(e.getSource()=打印文本)try print=getToolkit().getPrintJob(new JFrame(),打印,newProperties(); g=print.getGraphics(); g.translate(120,200); messPanel.printAll(g); g.dispose(); print
32、.end(); catch(Exception exp) elseif(e.getSource()=打印照片)try print=getToolkit().getPrintJob(new JFrame(),打印,newProperties(); g=print.getGraphics();int w=messPanel.getBounds().width; g.translate(120+w,200); pic.printAll(g); g.dispose(); print.end(); catch(Exception exp) publicvoid clearMess()车牌号.setTex
33、t(null);XX.setText(null);购车公司.setText(null);购车时间.setText(null);档次.setText(null); pic.setImage(null); pic.repaint(); /3.8Delete类class Delete extends JPanel implementsActionListener HashMap根本信息表=null; JTextField 车牌号,XX,档次,购车公司,购车时间; JRadioButton 男,女; utton 删除; ButtonGroup group=null;FileInputStream in
34、One=null;ObjectInputStream inTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File systemFile=null;public Delete(File file) systemFile=file;车牌号=new JTextField(10);删除=new utton(删除);车牌号.addActionListener(this);删除.addActionListener(this);XX=new JTextField(10);XX.setEditable(false);档
35、次=new JTextField(10);档次.setEditable(false);购车公司=new JTextField(10);购车公司.setEditable(false);购车时间=new JTextField(10);购车时间.setEditable(false);男=newJRadioButton(男,false);女=new JRadioButton(女,false); group=new ButtonGroup(); group.add(男); group.add(女); Box box1=Box.createHorizontalBox(); box1.add(new JLa
36、bel(输入要删除的车牌号:,JLabel.CENTER); box1.add(车牌号); box1.add(删除); Box box2=Box.createHorizontalBox(); box2.add(new JLabel(车主XX:,JLabel.CENTER); box2.add(XX); Box box3=Box.createHorizontalBox(); box3.add(new JLabel(性别:,JLabel.CENTER); box3.add(男); box3.add(女); Box box4=Box.createHorizontalBox(); box4.add(n
37、ew JLabel(档次:,JLabel.CENTER); box4.add(档次); Box box5=Box.createHorizontalBox(); box5.add(new JLabel(购车公司:,JLabel.CENTER); box5.add(购车公司); Box box6=Box.createHorizontalBox(); box6.add(new JLabel(购车时间:,JLabel.CENTER); box6.add(购车时间); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(Box.createVerticalGlue(); JPanel pCenter=new JPanel(); pCenter.add(boxH); setLayout(