java车辆管理系统_第1页
java车辆管理系统_第2页
java车辆管理系统_第3页
java车辆管理系统_第4页
java车辆管理系统_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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=g

2、etToolkit(); public void setImage(File imageFile) this.imageFile=imageFile; repaint(); Override public void paintComponent(Graphics g) super.paintComponent(g); int w=getBounds().width; int h=getBounds().height; if(imageFile!=null) Image image=tool.getImage(imageFile.getAbsolutePath(); g.drawImage(im

3、age, 0,0,w,h, this); /3.3Car类class Car implements Serializable String number,name,discipling,grade,borth,sex; File imagePic; public void setNumber(String number) this.number=number; public String getNumber() return number; public void setName(String name) =name; public String getName() retu

4、rn name; public void setDiscipling(String discipling) this.discipling=discipling; public String getDiscipling() return discipling; public void setGrade(String grade) this.grade=grade; public String getGrade() return grade; public void setBorth(String borth) this.borth=borth; public String getBorth()

5、 return borth; public void setSex(String sex) this.sex=sex; public String getSex() return sex; public void setImagePic(File image) imagePic=image; public File getImagePic() return imagePic; /3.5InputCar类class InputCar extends JPanel implements ActionListener Car 车主=null; CarPicture pic; HashMap<S

6、tring,Car>基本信息表=null; JTextField 车牌号,姓名,购车公司,购车时间; JButton 选择照片; JComboBox 档次; JRadioButton 男,女; ButtonGroup group=null; JButton 录入,重置; FileInputStream inOne=null; ObjectInputStream inTwo=null; FileInputStream outOne=null; ObjectOutputStream outTwo=null; File systemFile,imagePic; public InputCar(

7、File file) systemFile=file; pic=new CarPicture(); 车牌号=new JTextField(5); 姓名=new JTextField(5); 档次=new JComboBox(); try FileReader inOne = new FileReader("专业.txt"); BufferedReader inTwo = new BufferedReader(inOne); String s = null; int i=0; while(s=inTwo.readLine()!=null) 档次.addItem(s); inO

8、ne.close(); inTwo.close(); catch(IOException exp) 档次.addItem("高级"); 档次.addItem("中高级"); 档次.addItem("中级"); 档次.addItem("中低级"); 档次.addItem("普通"); 购车公司=new JTextField(5); 购车时间=new JTextField(5); 选择照片=new JButton("选择"); group=new ButtonGroup(); 男

9、=new JRadioButton("男",true); 女=new JRadioButton("女",true); group.add(男); group.add(女); 录入=new JButton("录入"); 重置=new JButton("重置"); 录入.addActionListener(this); 选择照片.addActionListener(this); 重置.addActionListener(this); Box box1=Box.createHorizontalBox(); box1.ad

10、d(new JLabel("车牌号:",JLabel.CENTER); 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.create

11、HorizontalBox(); 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

12、 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 picPanel=new JPanel(); picPanel.setBackground(Color.green); picPanel.add(new JLabel("选择照片:",JLabel.CENTER); picPanel.add(

13、选择照片); JPanel putButton=new JPanel(); putButton.add(录入); putButton.add(重置); JPanel messPanel=new JPanel(); messPanel.add(boxH); messPanel.setBackground(Color.cyan); putButton.setBackground(Color.red); setLayout(new BorderLayout(); JSplitPane splitV=new JSplitPane(JSplitPane.VERTICAL_SPLIT,picPanel,p

14、ic); JSplitPane splitH=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,messPanel,splitV); add(splitH,BorderLayout.CENTER); add(putButton,BorderLayout.SOUTH); validate(); public void actionPerformed(ActionEvent e) if(e.getSource()=录入) String number="" number=车牌号.getText(); if(number.length()>

15、0) try inOne =new FileInputStream(systemFile); inTwo =new ObjectInputStream(inOne); 基本信息表=(HashMap<String,Car>)inTwo.readObject(); inOne.close(); inTwo.close(); catch(Exception ee) if(基本信息表.containsKey(number) String warning="该生基本信息已存在,请到修改页面修改!" JOptionPane.showMessageDialog(this,wa

16、rning, "警告",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=(String)档次.getSele

17、ctedItem(); String grade=购车公司.getText(); String borth=购车时间.getText(); String sex=null; if(男.isSelected() sex=男.getText(); else sex=女.getText(); 车主=new Car(); 车主.setNumber(number); 车主.setName(name); 车主.setDiscipling(discipling); 车主.setGrade(grade); 车主.setBorth(borth); 车主.setSex(sex); 车主.setImagePic(i

18、magePic); try FileOutputStream outOne=new FileOutputStream(systemFile); outTwo=new ObjectOutputStream(outOne); 基本信息表.put(number,车主); outTwo.writeObject(基本信息表); outTwo.close(); outOne.close(); clearMess(); catch(Exception ee) else String warning="必须要输入学号!" JOptionPane.showMessageDialog(this

19、,warning,"警告",JOptionPane.WARNING_MESSAGE); else if(e.getSource()=选择照片) JFileChooser chooser=new JFileChooser(); FileNameExtensionFilter filter=new FileNameExtensionFilter("JPG&GIF Images","jpg","gif"); chooser.setFileFilter(filter); int state=chooser.show

20、OpenDialog(null); File choiceFile=chooser.getSelectedFile(); if(choiceFile!=null&&state=JFileChooser.APPROVE_OPTION) 选择照片.setText(choiceFile.getName(); imagePic=choiceFile; pic.setImage(imagePic); pic.repaint(); else if(e.getSource()=重置) clearMess(); public void clearMess() 车牌号.setText(null)

21、; 姓名.setText(null); 购车公司.setText(null); 购车时间.setText(null); 选择照片.setText("选择"); imagePic=null; pic.setImage(imagePic); pic.repaint(); /3.6inquset类class Inquest extends JDialog implements ActionListener CarPicture pic; PrintJob print; Graphics g=null; HashMap<String,Car>基本信息表; JTextFi

22、eld 车牌号,姓名,档次,购车公司,购车时间; JRadioButton 男,女; JButton 查询,打印文本及照片,打印文本,打印照片; ButtonGroup group=null; FileInputStream inOne=null; ObjectInputStream inTwo=null; File systemFile=null; JPanel messPanel; Car stu; public Inquest(File file) setTitle("查询对话框"); setModal(false); systemFile=file; pic =ne

23、w CarPicture(); 车牌号=new JTextField(6); 查询=new JButton("查询"); 车牌号.addActionListener(this); 查询.addActionListener(this); 打印文本及照片=new JButton("打印文本及照片"); 打印文本=new JButton("打印文本"); 打印照片=new JButton("打印照片"); 打印文本及照片.addActionListener(this); 打印文本.addActionListener(th

24、is); 打印照片.addActionListener(this); 打印文本及照片.setEnabled(false); 打印文本.setEnabled(false); 打印照片.setEnabled(false); 姓名=new JTextField(5); 姓名.setEditable(false); 档次=new JTextField(5); 档次.setEditable(false); 购车公司=new JTextField(5); 购车公司.setEditable(false); 购车时间=new JTextField(5); 购车时间.setEditable(false); 男=

25、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

26、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.createHorizontal

27、Box(); 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); box

28、H.add(box6); messPanel=new JPanel(); messPanel.add(boxH); JSplitPane splitH=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,messPanel,pic); add(splitH,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(打印文本及照片); pSouth.add(打印文本); pSouth.add(打印照片); add(pSouth,BorderLayout.SOUTH); validate(); set

29、Visible(false); setSize(360,230); addWindowListener(new WindowAdapter() Override public void windowClosing(WindowEvent e) setVisible(false);); public void actionPerformed(ActionEvent e) if(e.getSource()=查询|e.getSource()=车牌号) String number="" number=车牌号.getText(); if(number.length()>0) t

30、ry inOne=new FileInputStream(systemFile); inTwo=new ObjectInputStream(inOne); 基本信息表=(HashMap<String,Car>)inTwo.readObject(); inOne.close(); inTwo.close(); catch(Exception ee) if(基本信息表.containsKey(number) stu=基本信息表.get(number); 姓名.setText(stu.getName(); 档次.setText(stu.getDiscipling(); 购车公司.setT

31、ext(stu.getGrade(); 购车时间.setText(stu.getBorth(); if(stu.getSex().equals("男") 男.setSelected(true); else 女.setSelected(true); pic.setImage(stu.getImagePic(); pic.repaint(); 打印文本及照片.setEnabled(true); 打印文本.setEnabled(true); 打印照片.setEnabled(true); else 打印文本及照片.setEnabled(false); 打印文本.setEnabled

32、(false); 打印照片.setEnabled(false); String warning="该车牌号不存在!" JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); clearMess(); else 打印文本及照片.setEnabled(false); 打印文本.setEnabled(false); 打印照片.setEnabled(false); String warning="必须要输入车牌号!" JOptionPane.s

33、howMessageDialog(this,warning,"警告", JOptionPane.WARNING_MESSAGE); else if(e.getSource()=打印文本及照片) try print=getToolkit().getPrintJob(new JFrame(),"打印",new Properties(); g=print.getGraphics(); g.translate(120,200); int w=messPanel.getBounds().width; messPanel.printAll(g); g.transla

34、te(w,0); pic.printAll(g); 姓名.setText(stu.getName(); g.dispose(); print.end(); catch(Exception exp) else if(e.getSource()=打印文本) try print=getToolkit().getPrintJob(new JFrame(),"打印",new Properties(); g=print.getGraphics(); g.translate(120,200); messPanel.printAll(g); g.dispose(); print.end()

35、; catch(Exception exp) else if(e.getSource()=打印照片) try print=getToolkit().getPrintJob(new JFrame(),"打印",new Properties(); g=print.getGraphics(); int w=messPanel.getBounds().width; g.translate(120+w,200); pic.printAll(g); g.dispose(); print.end(); catch(Exception exp) public void clearMess(

36、) 车牌号.setText(null); 姓名.setText(null); 购车公司.setText(null); 购车时间.setText(null); 档次.setText(null); pic.setImage(null); pic.repaint(); /3.8Delete类class Delete extends JPanel implements ActionListener HashMap<String,Car>基本信息表=null; JTextField 车牌号,姓名,档次,购车公司,购车时间; JRadioButton 男,女; JButton 删除; Butt

37、onGroup group=null; FileInputStream inOne=null; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; File systemFile=null; public Delete(File file) systemFile=file; 车牌号=new JTextField(10); 删除=new JButton("删除"); 车牌号.addActionListener(this); 删除.addActio

38、nListener(this); 姓名=new JTextField(10); 姓名.setEditable(false); 档次=new JTextField(10); 档次.setEditable(false); 购车公司=new JTextField(10); 购车公司.setEditable(false); 购车时间=new JTextField(10); 购车时间.setEditable(false); 男=new JRadioButton("男",false); 女=new JRadioButton("女",false); group=new

39、 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(姓名); Box box3=Box.createHorizonta

40、lBox(); 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 bo

41、x6=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(new BorderLayout(); add(pCenter,BorderLayout.CENTER); validate(); public void actionPerformed(ActionEvent e) if(e.getSource()=删除|e.getSource()=车牌号) Strin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论