基于java实现停车场管理系统
本文实例为大家分享了java停车场管理系统的具体代码,供大家参考,具体内容如下
WorkFram.java
packagecom.parking;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.*;
/*
*WotkFram.java
*
*Createdon2008年9月2日,下午7:57
*/
/**
*
*@authorcheng
*/
publicclassWorkFramextendsJFrame{
/**
*
*/
privatestaticfinallongserialVersionUID=1L;
/**
*@paramargsthecommandlinearguments
*/
//变量声明-不进行修改//GEN-BEGIN:variables
privateJButtonjbtnEnter;
privateJButtonjbtnRefrush;
privateJTextAreajtexInfor;
publicintm_areaCount;//停车区个数
publicint[]m_nos;//每个停车区的车位数
publicint[]m_apare;//每个停车区的空闲车位数
//变量声明结束//GEN-END:variables
//intm_areaCount;
/**CreatesnewformWotkFram*/
publicWorkFram(InitFramefrm){
this.m_areaCount=frm.m_Area.length;
this.m_apare=newint[m_areaCount];
this.m_nos=newint[m_areaCount];
for(inti=0;i//GEN-BEGIN:initComponents
privatevoidinitComponents(){
jbtnEnter=newJButton();
jbtnRefrush=newJButton();
jtexInfor=newJTextArea("停车场初始化结果:\n"+getStopStatus());
jtexInfor.setEnabled(false);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setTitle("\u505c\u8f66\u573a\u6a21\u62df");
jbtnEnter.setText("\u8fdb\u5165\u505c\u8f66\u573a");
jbtnRefrush.setText("刷新");
jbtnEnter.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnEnterActionPerformed(evt);
}
});
jbtnRefrush.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnRefrushActionPerformed(evt);
}
});
GroupLayoutlayout=newGroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(GroupLayout.Alignment.TRAILING,layout.createSequentialGroup()
.addContainerGap(159,Short.MAX_VALUE)
.addComponent(jtexInfor)
.addComponent(jbtnRefrush)
.addComponent(jbtnEnter)
.addGap(128,128,128))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(GroupLayout.Alignment.TRAILING,layout.createSequentialGroup()
.addContainerGap(204,Short.MAX_VALUE)
.addComponent(jtexInfor)
.addComponent(jbtnRefrush)
.addComponent(jbtnEnter)
.addGap(73,73,73))
);
pack();
}////GEN-END:initComponents
privatevoidjbtnEnterActionPerformed(ActionEventevt){//GEN-FIRST:event_jbtnEnterActionPerformed
//TODO将在此处添加您的处理代码:
Threadthr=newcarThread(this);
thr.run();
}//GEN-LAST:event_jbtnEnterActionPerformed
privatevoidjbtnRefrushActionPerformed(ActionEventevt){//GEN-FIRST:event_jbtnEnterActionPerformed
//TODO将在此处添加您的处理代码:
this.jtexInfor.setText("停车场当前车区车位状况统计:\n"+getStopStatus());
}//GEN-LAST:event_jbtnEnterActionPerformed
publicStringgetStopStatus(){
Stringstr="";
for(inti=0;i0){
str+=""+(i+1)+"区总车位:"+m_nos[i]+"\t当前空闲车位"+m_apare[i]+"个\n";
}else{
str+=""+(i+1)+"区总车位:"+m_nos[i]+"\t当前区无空闲车位\n";
}
}
returnstr;
}
publicvoidsetInfor(Stringinfor){
this.jtexInfor.setText(infor);
}
}
InitFrame.java
packagecom.parking;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.WindowAdapter;
importjava.awt.event.WindowEvent;
importjavax.swing.*;
/*
*InitFrame.java
*
*Createdon2008年9月2日,下午7:36
*/
/**
*
*@authorcheng
*/
publicclassInitFrameextendsJFrame{
//变量声明-不进行修改
//GEN-BEGIN:variables
/**
*
*/
privatestaticfinallongserialVersionUID=1L;
privateJButtonjButton1;
privateJLabeljLabel1;
privateJLabeljLabel2;
privateJLabeljLabel3;
privateJSpinnerjSpinnerStopArea;
privateJButtonjbtnCancel;
privateJButtonjbtnOK;
publicJButtonjbtnStopCount;
privateJTextFieldjtxtCarCount;
privateJTextFieldjtxtStopCount;
publicintm_Area[];
SpinnerNumberModelmdl;
//变量声明结束//GEN-END:variables
/**CreatesnewformInitFrame*/
publicInitFrame(){
initComponents();
mdl=newSpinnerNumberModel();
this.jSpinnerStopArea.setModel(mdl);
}
/**Thismethodiscalledfromwithintheconstructorto
*initializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodis
*alwaysregeneratedbytheFormEditor.
*/
////GEN-BEGIN:initComponents
privatevoidinitComponents(){
jLabel1=newJLabel();
jtxtStopCount=newJTextField();
jbtnStopCount=newJButton();
jLabel2=newJLabel();
jSpinnerStopArea=newJSpinner();
jLabel3=newJLabel();
jtxtCarCount=newJTextField();
jButton1=newJButton();
jbtnOK=newJButton();
jbtnCancel=newJButton();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setTitle("\u505c\u8f66\u573a\u521d\u59cb\u5316");
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEventevt){
formWindowClosing(evt);
}
});
jLabel1.setText("\u505c\u8f66\u533a\u57df\u4e2a\u6570\uff1a");
jbtnStopCount.setText("\u8f93\u5165\u505c\u533a\u4e2a\u6570");
jbtnStopCount.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnStopCountActionPerformed(evt);
}
});
jLabel2.setText("\u505c\u8f66\u533a\u53f7\uff1a");
jSpinnerStopArea.setEnabled(false);
jLabel3.setText("\u505c\u8f66\u4f4d\u4e2a\u6570\uff1a");
jtxtCarCount.setEnabled(false);
jButton1.setText("\u8f93\u5165\u505c\u533a\u8f66\u4f4d\u4e2a\u6570");
jButton1.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jButton1ActionPerformed(evt);
}
});
jbtnOK.setText("\u786e\u5b9a");
jbtnOK.setEnabled(false);
jbtnOK.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnOKActionPerformed(evt);
}
});
jbtnCancel.setText("\u53d6\u6d88");
jbtnCancel.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnCancelActionPerformed(evt);
}
});
GroupLayoutlayout=newGroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSpinnerStopArea,GroupLayout.PREFERRED_SIZE,37,GroupLayout.PREFERRED_SIZE)
.addGap(14,14,14)
.addComponent(jLabel3,GroupLayout.PREFERRED_SIZE,81,GroupLayout.PREFERRED_SIZE)
.addGap(13,13,13)
.addComponent(jtxtCarCount,GroupLayout.PREFERRED_SIZE,117,GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(24,24,24)
.addComponent(jtxtStopCount,GroupLayout.PREFERRED_SIZE,99,GroupLayout.PREFERRED_SIZE)
.addGap(25,25,25)
.addComponent(jbtnStopCount))))
.addGroup(layout.createSequentialGroup()
.addGap(29,29,29)
.addComponent(jButton1,GroupLayout.DEFAULT_SIZE,137,Short.MAX_VALUE)
.addGap(22,22,22)
.addComponent(jbtnOK,GroupLayout.DEFAULT_SIZE,65,Short.MAX_VALUE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbtnCancel,GroupLayout.PREFERRED_SIZE,66,GroupLayout.PREFERRED_SIZE)
.addGap(23,23,23)))
.addGap(51,51,51))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(30,30,30)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jtxtStopCount,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)
.addComponent(jbtnStopCount))
.addGap(27,27,27)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jSpinnerStopArea,GroupLayout.PREFERRED_SIZE,15,GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3,GroupLayout.PREFERRED_SIZE,15,GroupLayout.PREFERRED_SIZE)
.addComponent(jtxtCarCount,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)))
.addGap(76,76,76)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jbtnOK)
.addComponent(jbtnCancel))
.addContainerGap(100,Short.MAX_VALUE))
);
pack();
}////GEN-END:initComponents
privatevoidjbtnCancelActionPerformed(ActionEventevt){//GEN-FIRST:event_jbtnCancelActionPerformed
//TODO将在此处添加您的处理代码:
JOptionPane.showMessageDialog(null,"您没有初始化,无法执行");
System.exit(-1);
}//GEN-LAST:event_jbtnCancelActionPerformed
privatevoidjbtnOKActionPerformed(ActionEventevt){//GEN-FIRST:event_jbtnOKActionPerformed
//TODO将在此处添加您的处理代码:
this.setVisible(false);
this.removeNotify();
WorkFramfrm=newWorkFram(this);
//setValue(frm);
frm.setVisible(true);
}//GEN-LAST:event_jbtnOKActionPerformed
privatevoidformWindowClosing(WindowEventevt){//GEN-FIRST:event_formWindowClosing
//TODO将在此处添加您的处理代码:
JOptionPane.showMessageDialog(null,"您没有初始化,无法执行");
System.exit(-1);
}//GEN-LAST:event_formWindowClosing
privatevoidjButton1ActionPerformed(ActionEventevt){//GEN-FIRST:event_jButton1ActionPerformed
//TODO将在此处添加您的处理代码:
booleanb=true;
intn=((Integer)mdl.getValue()).intValue()-1;
this.m_Area[n]=Integer.parseInt(this.jtxtCarCount.getText());
for(inti=0;i
carThread.java
packagecom.parking;
/*
*carThread.java
*
*Createdon2008年9月2日,下午9:02
*
*Tochangethistemplate,chooseTools|TemplateManager
*andopenthetemplateintheeditor.
*/
/**
*
*@authorcheng
*/
publicclasscarThreadextendsThread{
privateWorkFramfrm;
/**CreatesanewinstanceofcarThread*/
publiccarThread(WorkFramfrm){
this.frm=frm;
}
publicvoidrun(){
newcarJFrame(frm).setVisible(true);
}
}
carJFrame.java
packagecom.parking;
/*
*carJFrame.java
*
*Createdon2008年9月2日,下午9:01
*/
/**
*
*@authorcheng
*/
importjavax.swing.*;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.WindowAdapter;
importjava.awt.event.WindowEvent;
publicclasscarJFrameextendsJFrame{
/**
*
*/
privatestaticfinallongserialVersionUID=1L;
/**
*@paramargsthecommandlinearguments
*/
//变量声明-不进行修改//GEN-BEGIN:variables
privateJButtonjbtnEnterStop;
privateJButtonjbtnLeftArea;
privateJButtonjbtnLeftStop;
privateJButtonjbtnLookUpArea;
privateJButtonjbtnLookupPosition;
privateWorkFrammainFram;
privateintchooseArea;
//变量声明结束//GEN-END:variables
/**CreatesnewformcarJFrame*/
publiccarJFrame(WorkFramfrm){
initComponents();
mainFram=frm;
}
/**Thismethodiscalledfromwithintheconstructorto
*initializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodis
*alwaysregeneratedbytheFormEditor.
*/
////GEN-BEGIN:initComponents
privatevoidinitComponents(){
jbtnEnterStop=newJButton();
jbtnLookUpArea=newJButton();
jbtnLookupPosition=newJButton();
jbtnLeftArea=newJButton();
jbtnLeftStop=newJButton();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setTitle("\u505c\u8f66\u573a\u64cd\u4f5c");
jbtnEnterStop.setText("\u8fdb\u5165\u505c\u8f66\u573a");
jbtnEnterStop.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnEnterStopActionPerformed(evt);
}
});
jbtnLookUpArea.setText("\u5bfb\u627e\u505c\u8f66\u533a");
jbtnLookUpArea.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnLookUpAreaActionPerformed(evt);
}
});
jbtnLookupPosition.setText("\u5bfb\u627e\u505c\u8f66\u4f4d");
jbtnLookupPosition.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnLookupPositionActionPerformed(evt);
}
});
jbtnLeftArea.setText("\u79bb\u5f00\u505c\u8f66\u533a");
jbtnLeftArea.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnLeftAreaActionPerformed(evt);
}
});
jbtnLeftStop.setText("\u79bb\u5f00\u505c\u8f66\u573a");
jbtnLeftStop.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
jbtnLeftStopActionPerformed(evt);
}
});
jbtnEnterStop.setEnabled(true);
jbtnLookUpArea.setEnabled(false);
jbtnLookupPosition.setEnabled(false);
jbtnLeftArea.setEnabled(false);
jbtnLeftStop.setEnabled(false);
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEventevt){
formWindowClosing(evt);
}
});
GroupLayoutlayout=newGroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(102,102,102)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(jbtnLeftStop)
.addComponent(jbtnLeftArea)
.addComponent(jbtnLookupPosition)
.addComponent(jbtnLookUpArea)
.addComponent(jbtnEnterStop))
.addContainerGap(205,Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(56,56,56)
.addComponent(jbtnEnterStop)
.addGap(20,20,20)
.addComponent(jbtnLookUpArea)
.addGap(22,22,22)
.addComponent(jbtnLookupPosition)
.addGap(24,24,24)
.addComponent(jbtnLeftArea)
.addGap(19,19,19)
.addComponent(jbtnLeftStop)
.addContainerGap(44,Short.MAX_VALUE))
);
pack();
}////GEN-END:initComponents
privatevoidjbtnLeftStopActionPerformed(ActionEventevt){//GEN-FIRST:event_jbtnLeftStopActionPerformed
//TODO将在此处添加您的处理代码:
//离开停车场,交存车卡
JOptionPane.showMessageDialog(null,"停车卡收回,再见!");
/*jbtnEnterStop.setEnabled(true);
jbtnLookUpArea.setEnabled(false);
jbtnLookupPosition.setEnabled(false);
jbtnLeftArea.setEnabled(false);
jbtnLeftStop.setEnabled(false);
*/
this.setVisible(false);
this.removeNotify();
}//GEN-LAST:event_jbtnLeftStopActionPerformed
privatevoidjbtnLeftAreaActionPerformed(ActionEventevt){//GEN-FIRST:event_jbtnLeftAreaActionPerformed
//TODO将在此处添加您的处理代码:
//离开停车区
intconfirm=JOptionPane.showConfirmDialog(null,"确定要离开"+chooseArea+"号停车区?","离开停车区",JOptionPane.YES_NO_OPTION);
if(confirm==JOptionPane.YES_OPTION){
mainFram.m_apare[chooseArea-1]++;
//mainFram.setInfor(mainFram.getStopStatus());
jbtnLeftArea.setEnabled(false);
jbtnLookUpArea.setEnabled(true);
jbtnLeftStop.setEnabled(true);
}elseif(confirm==JOptionPane.NO_OPTION){
JOptionPane.showMessageDialog(null,"您已放弃了离开该车区!");
jbtnLookUpArea.setEnabled(true);
}
}//GEN-LAST:event_jbtnLeftAreaActionPerformed
privatevoidjbtnLookupPositionActionPerformed(ActionEventevt){//GEN-FIRST:event_jbtnLookupPositionActionPerformed
//TODO将在此处添加您的处理代码:
//进入停车区,寻找停车位
intconfirm=JOptionPane.showConfirmDialog(null,"您已经选择了"+chooseArea+"号停车区,"+"确定要进入该停车区?","进行停车区寻找车位",JOptionPane.YES_NO_OPTION);
if(confirm==JOptionPane.YES_OPTION){
mainFram.m_apare[chooseArea-1]--;
//mainFram.setInfor(mainFram.getStopStatus());
jbtnLookUpArea.setEnabled(false);
jbtnLookupPosition.setEnabled(false);
jbtnLeftArea.setEnabled(true);
jbtnLeftStop.setEnabled(false);
}elseif(confirm==JOptionPane.NO_OPTION){
JOptionPane.showMessageDialog(null,"您已放弃了进入该车区!");
jbtnLookUpArea.setEnabled(true);
jbtnLookupPosition.setEnabled(false);
}
}//GEN-LAST:event_jbtnLookupPositionActionPerformed
privatevoidjbtnLookUpAreaActionPerformed(ActionEventevt){//GEN-FIRST:event_jbtnLookUpAreaActionPerformed
//TODO将在此处添加您的处理代码:
//进入停车场,寻找停车区
ImageIconicon=newImageIcon("test.gif");
int[]freeArea=getFreeArea();
Object[]freeAreas=newObject[freeArea.length];
for(inti=0;i0){
isFull=false;
}
}
if(isFull){
JOptionPane.showMessageDialog(null,"当前车场无空闲车区,请稍后再试!");
}else{
jbtnEnterStop.setEnabled(false);
jbtnLookUpArea.setEnabled(true);
jbtnLookupPosition.setEnabled(false);
jbtnLeftArea.setEnabled(false);
jbtnLeftStop.setEnabled(false);
JOptionPane.showMessageDialog(null,"成功领取停车卡,请进去车场寻找停车区位!");
}
}//GEN-LAST:event_jbtnEnterStopActionPerformed
privatevoidformWindowClosing(WindowEventevt){//GEN-FIRST:event_formWindowClosing
//TODO将在此处添加您的处理代码:
intconfirm=JOptionPane.showConfirmDialog(null,"确定退出?","退出停车区",JOptionPane.YES_NO_OPTION);
if(confirm==JOptionPane.YES_OPTION){
if(chooseArea>0){
mainFram.m_apare[chooseArea-1]--;
}
this.setVisible(false);
this.removeNotify();
}else{
this.setVisible(true);
}
}//GEN-LAST:event_formWindowClosing
publicint[]getFreeArea(){
intcount=0;
for(inti=0;i0){
count++;
}
}
int[]freeArea=newint[count];
for(inti=0,j=0;i0){
freeArea[j++]=i+1;
}
}
returnfreeArea;
}
}
源码下载:java停车场管理系统
更多学习资料请关注专题《管理系统开发》。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。