java车辆管理系统方案.docx
《java车辆管理系统方案.docx》由会员分享,可在线阅读,更多相关《java车辆管理系统方案.docx(13页珍藏版)》请在冰豆网上搜索。
java车辆管理系统方案
//车辆管理系统packagejavaapplication27;importjavax.swing.*;
importjava.io.*;
importjava.awt.*;
importjava.awt.event.*;
importjava.util.*;
importjavax.swing.filechooser.*;
importjava.io.FileInputStream;
//3.4CarPicture类classCarPictureextendsJPanel{FileimageFile;
Toolkittool;
publicCarPicture()
{tool=getToolkit();
}
publicvoidsetImage(FileimageFile)
{this.imageFile=imageFile;repaint();
}
@Override
publicvoidpaintComponent(Graphicsg)
{super.paintComponent(g);intw=getBounds().width;inth=getBounds().height;if(imageFile!
=null)
{Imageimage=tool.getImage(imageFile.getAbsolutePath());g.drawImage(image,0,0,w,h,this);
}
}
}
//3.3Car类
classCarimplementsSerializable
{Stringnumber,name,discipling,grade,borth,sex;
FileimagePic;
publicvoidsetNumber(Stringnumber)
{this.number=number;
}
publicStringgetNumber()
{returnnumber;
}
publicvoidsetName(Stringname)
{this.name=name;
}
publicStringgetName()
{returnname;
}
publicvoidsetDiscipling(Stringdiscipling)
{this.discipling=discipling;
}
publicStringgetDiscipling()
{returndiscipling;
}
publicvoidsetGrade(Stringgrade)
{this.grade=grade;
}
publicStringgetGrade()
{returngrade;
}
publicvoidsetBorth(Stringborth)
{this.borth=borth;
}
publicStringgetBorth()
{returnborth;
}
publicvoidsetSex(Stringsex)
{this.sex=sex;
}
publicStringgetSex()
{returnsex;
}
publicvoidsetImagePic(Fileimage)
{imagePic=image;
}
publicFilegetImagePic()
{returnimagePic;
}
}
//3.5InputCar类
classInputCarextendsJPanelimplementsActionListener
{Car车主=null;
CarPicturepic;
HashMap基本信息表=null;
JTextField车牌号,姓名,购车公司,购车时间;
JButton选择照片;
JComboBox档次;JRadioButton男,女;
ButtonGroupgroup=null;
JButton录入,重置;
FileInputStreaminOne=null;
ObjectInputStreaminTwo=null;
FileInputStreamoutOne=null;
ObjectOutputStreamoutTwo=null;
FilesystemFile,imagePic;
publicInputCar(Filefile)
{systemFile=file;
pic=newCarPicture();车牌号=newJTextField(5);
姓名=newJTextField(5);
档次=newJComboBox();
try{FileReaderinOne=newFileReader("专业.txt");
BufferedReaderinTwo=newBufferedReader(inOne);Strings=null;
inti=0;
while((s=inTwo.readLine())!
=null)
档次.addItem(s);
inOne.close();inTwo.close();
catch(IOExceptionexp){
档次.addItem("高级");
档次.addItem("中高级");档次.addItem("中级");
档次.addItem("中低级");
档次.additem(”普通");
}
购车公司=newJTextField(5);
购车时间=newJTextField(5);
选择照片=newJButton("选择");
group=newButtonGroup();
男=newJRadioButton("男",true);女=newJRadioButton("女",true);
group.add(男);
group.add(女);
录入=newJButton("录入");重置=newJButton("重置");
录入.addActionListener(this);选择照片.addActionListener(this);
重置.addActionListener(this);
Boxbox1=Box.createHorizontalBox();
box1.add(newJLabel("车牌号:
",JLabel.CENTER));box1.add(车牌号);
Boxbox2=Box.createHorizontalBox();
box2.add(newJLabel("车主姓名:
",JLabel.CENTER));
box2.add(姓名);
Boxbox3=Box.createHorizontalBox();
box3.add(newJLabel("车主性别:
",JLabel.CENTER));
box3.add(男);
box3.add(女);
Boxbox4=Box.createHorizontalBox();
box4.add(newJLabel("车辆档次:
",JLabel.CENTER));
box4.add(档次);
Boxbox5=Box.createHorizontalBox();
box5.add(newJLabel("购车公司:
",JLabel.CENTER));
box5.add(购车公司);
Boxbox6=Box.createHorizontalBox();
box6.add(newJLabel("购车时间:
",JLabel.CENTER));
box6.add(购车时间);
BoxboxH=Box.createVerticalBox();
boxH.add(box1);
boxH.add(box2);
boxH.add(box3);
boxH.add(box4);
boxH.add(box5);
boxH.add(box6);boxH.add(Box.createVerticalGlue());
JPanelpicPanel=newJPanel();picPanel.setBackground(Color.green);picPanel.add(newJLabel("选择照片:
",JLabel.CENTER));picPanel.add(选择照片);
JPanelputButton=newJPanel();
putButton.add(录入);
putButton.add(重置);
JPanelmessPanel=newJPanel();
messPanel.add(boxH);messPanel.setBackground(Color.cyan);
putButton.setBackground(Color.red);
setLayout(newBorderLayout());
JSplitPanesplitV=newJSplitPane(JSplitPane.VERTICAL_SPLIT,picPanel,pic);
JSplitPanesplitH=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,messPanel,splitV);add(splitH,BorderLayout.CENTER);
add(putButton,BorderLayout.SOUTH);
validate();
}
publicvoidactionPerformed(ActionEvente){if(e.getSource()==录入){
Stringnumber="";
number=车牌号.getText();if(number.length()>0){
try{
inOne=newFileInputStream(systemFile);
inTwo=newObjectInputStream(inOne);
基本信息表=(HashMap)inTwo.readObject();inOne.close();
inTwo.close();
}
catch(Exceptionee){}
if(基本信息表.containsKey(number)){
Stringwarning="该生基本信息已存在,请到修改页面修改!
JOptionPane.showMessageDialog(this,warning,"警告
",JOptionPane.WARNING_MESSAGE);
}
else{
Stringm="基本信息将被录入!
";
intok=JOptionPane.showConfirmDialog(this,m,"确认
",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
if(ok==JOptionPane.YES_OPTION){
Stringname=
Stringdiscipling=(String)
姓名.getText();
档次.getSelectedItem();
String