电梯模拟程序Java语言编写.docx

上传人:b****2 文档编号:385826 上传时间:2022-10-09 格式:DOCX 页数:20 大小:17.04KB
下载 相关 举报
电梯模拟程序Java语言编写.docx_第1页
第1页 / 共20页
电梯模拟程序Java语言编写.docx_第2页
第2页 / 共20页
电梯模拟程序Java语言编写.docx_第3页
第3页 / 共20页
电梯模拟程序Java语言编写.docx_第4页
第4页 / 共20页
电梯模拟程序Java语言编写.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

电梯模拟程序Java语言编写.docx

《电梯模拟程序Java语言编写.docx》由会员分享,可在线阅读,更多相关《电梯模拟程序Java语言编写.docx(20页珍藏版)》请在冰豆网上搜索。

电梯模拟程序Java语言编写.docx

importjava.awt.*;

importjavax.swing.*;

importjava.awt.event.*;

importjava.io.*;

publicclassLiftMainTest

{

publicstaticvoidmain(Stringargs[])

{

 newLiftTest("电梯测试");

 }

}

//批量数据测试对话框

classDialogextendsJDialogimplementsActionListener

{

intMessage=0;

JPanelDJPanel=newJPanel();

JTextFieldTestField[]=newJTextField[16];

JLabelTestLabel1=newJLabel("时间");

JLabelTestLabel2=newJLabel("人数");

JLabelTestLabel3=newJLabel("起始楼层");

JLabelTestLabel4=newJLabel("目标楼层");

JButtonok=newJButton("确定");

JButtoncancel=newJButton("取消");

Dialog(JFramef,Strings,booleanb)

{

super(f,s,b);

DJPanel.setLayout(newGridLayout(7,3));

for(inti=0;i<=15;i++)

{

TestField[i]=newJTextField(4);

}

DJPanel.add(TestLabel1);

DJPanel.add(TestLabel2);

DJPanel.add(TestLabel3);

DJPanel.add(TestLabel4);

DJPanel.add(TestField[0]);

DJPanel.add(TestField[1]);

DJPanel.add(TestField[2]);

DJPanel.add(TestField[3]);

DJPanel.add(TestField[4]);

DJPanel.add(TestField[5]);

DJPanel.add(TestField[6]);

DJPanel.add(TestField[7]);

DJPanel.add(TestField[8]);

DJPanel.add(TestField[9]);

DJPanel.add(TestField[10]);

DJPanel.add(TestField[11]);

DJPanel.add(TestField[12]);

DJPanel.add(TestField[13]);

DJPanel.add(TestField[14]);

DJPanel.add(TestField[15]);

DJPanel.add(ok);

DJPanel.add(cancel);

add(DJPanel);

ok.addActionListener(this);

cancel.addActionListener(this);

setBounds(450,170,300,300);

}

publicvoidactionPerformed(ActionEvente)//Dialog监听函数

{

if(e.getSource()==ok)

{

Message=1;

setVisible(false);

}

elseif(e.getSource()==cancel)

{

Message=-1;

setVisible(false);

}

else

{

;

}

}

}

//LiftTest类

classLiftTestextendsJFrameimplementsActionListener

{

Dialog mydialog;

JMenuBarmenubar;

JMenumenu,submenu,submenuhelp;

JMenuItemitem1,item2,menuitemhelp;

//变量定义

intx;

inty;

intLIsRun=0;//左电梯是否在运行(0或1)

intRIsRun=0;//右电梯是否在运行(0或1)

intLDirection=0;//左电梯运行方向

intRDirection=0;//右电梯运行方向

intLWantLevel=0;//乘客目的层数

intRWantLevel=0;

intLNowLevel=0;//乘客开始时所在层数

intRNowLevel=0;

intLLiftNowLevel=1;//左电梯目前所在层数

intRLiftNowLevel=1;//右电梯目前所在层数

intWantDirection=0;//乘客目标运行方向

intWaitPeopleNum[]=newint[11];//保留数组(未用)

inta=0;

intb=0;

//线程定义

LIOlio=newLIO();

RIOrio=newRIO();

ThreadLStartThread=newThread(lio);

ThreadRStartThread=newThread(rio);

//上下电梯的按钮定义

JButtonBlue10=newJButton(newImageIcon("10x.gif"));

JButtonBlue9=newJButton(newImageIcon("9x.gif"));

JButtonBlue8=newJButton(newImageIcon("8x.gif"));

JButtonBlue7=newJButton(newImageIcon("7x.gif"));

JButtonBlue6=newJButton(newImageIcon("6x.gif"));

JButtonBlue5=newJButton(newImageIcon("5x.gif"));

JButtonBlue4=newJButton(newImageIcon("4x.gif"));

JButtonBlue3=newJButton(newImageIcon("3x.gif"));

JButtonBlue2=newJButton(newImageIcon("2x.gif"));

JButtonRed9=newJButton(newImageIcon("9s.gif"));

JButtonRed8=newJButton(newImageIcon("8s.gif"));

JButtonRed7=newJButton(newImageIcon("7s.gif"));

JButtonRed6=newJButton(newImageIcon("6s.gif"));

JButtonRed5=newJButton(newImageIcon("5s.gif"));

JButtonRed4=newJButton(newImageIcon("4s.gif"));

JButtonRed3=newJButton(newImageIcon("3s.gif"));

JButtonRed2=newJButton(newImageIcon("2s.gif"));

JButtonRed1=newJButton(newImageIcon("1s.gif"));

//电梯门定义

JButtonLLiftLDoor=newJButton(newImageIcon("LLiftLDoor.gif"));//设置门图标

JButtonLLiftRDoor=newJButton(newImageIcon("LLiftRDoor.gif"));//设置门图标

JButtonRLiftLDoor=newJButton(newImageIcon("RLiftLDoor.gif"));//设置门图标

JButtonRLiftRDoor=newJButton(newImageIcon("RLiftRDoor.gif"));//设置门图标

//电梯内部按钮定义

JButtonLPressButton1=newJButton("1");

JButtonLPressButton2=newJButton("2");

JButtonLPressButton3=newJButton("3");

JButtonLPressButton4=newJButton("4");

JButtonLPressButton5=newJButton("5");

JButtonLPressButton6=newJButton("6");

JButtonLPressButton7=newJButton("7");

JButtonLPressButton8=newJButton("8");

JButtonLPressButton9=newJButton("9");

JButtonLPressButton10=newJButton("10");

JButtonRPressButton1=newJButton("1");

JButtonRPressButton2=newJButton("2");

JButtonRPressButton3=newJButton("3");

JButtonRPressButton4=newJButton("4");

JButtonRPressButton5=newJButton("5");

JButtonRPressButton6=newJButton("6");

JButtonRPressButton7=newJButton("7");

JButtonRPressButton8=newJButton("8");

JButtonRPressButton9=newJButton("9");

JButtonRPressButton10=newJButton("10");量数据测试”按钮的Panel

//组件定义

JLabelLL=newJLabel("当前电梯内部人数:

");

JLabelRL=newJLabel("当前电梯内部人数:

");

JButtonStart=newJButton("开始电梯调度模拟");//开始电梯调度模拟按钮

JButtonTest=newJButton("开始批量数据测试");//开始批量数据测试按钮

JTextAreaLTextArea=newJTextArea(5,5);

JTextAreaRTextArea=newJTextArea(5,5);

//电梯调度函数Cal(LIsRun,LLiftNowLevel,q,LDirection)

intCal(intx,inty,intz,intw)

{

 return(x*(y-z)*w);

}

//方法函数

LiftTest(Strings)

{

super(s);

setSize(1000,600);

setLocation(100,50);

//Dialog

 mydialog=newDialog(this,"批量数据测试",true);

//菜单项设置

menubar=newJMe

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > IT认证

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1