电梯模拟程序(Java语言编写)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.io.*;

public class LiftMainTest

{

public static void main(String args[])

{

new LiftTest("电梯测试");

}

}

//批量数据测试对话框

class Dialog extends JDialog implements ActionListener {

int Message=0;

JPanel DJPanel=new JPanel();

JTextField TestField[]=new JTextField[16];

JLabel TestLabel1=new JLabel("时间");

JLabel TestLabel2=new JLabel("人数");

JLabel TestLabel3=new JLabel("起始楼层");

JLabel TestLabel4=new JLabel("目标楼层");

JButton ok=new JButton("确定");

JButton cancel=new JButton("取消");

Dialog(JFrame f,String s,boolean b)

{

super(f,s,b);

DJPanel.setLayout(new GridLayout(7,3));

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

{

TestField[i]=new JTextField(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);

}

public void actionPerformed(ActionEvent e)//Dialog监听函数{

if(e.getSource()==ok)

{

Message=1;

setVisible(false);

}

else if(e.getSource()==cancel)

{

Message=-1;

setVisible(false);

}

else

{

;

}

}

}

//LiftTest类

class LiftTest extends JFrame implements ActionListener {

Dialog mydialog;

JMenuBar menubar;

JMenu menu,submenu,submenuhelp;

JMenuItem item1,item2,menuitemhelp;

//变量定义

int x;

int y;

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

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

int LDirection=0;//左电梯运行方向

int RDirection=0;//右电梯运行方向

int LWantLevel=0;//乘客目的层数

int RWantLevel=0;

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

int RNowLevel=0;

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

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

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

int WaitPeopleNum[]=new int[11];//保留数组(未用)

int a=0;

int b=0;

//线程定义

LIO lio=new LIO();

RIO rio=new RIO();

Thread LStartThread=new Thread(lio);

Thread RStartThread=new Thread(rio);

//上下电梯的按钮定义

JButton Blue10=new JButton(new ImageIcon("10x.gif"));

JButton Blue9=new JButton(new ImageIcon("9x.gif"));

JButton Blue8=new JButton(new ImageIcon("8x.gif"));

JButton Blue7=new JButton(new ImageIcon("7x.gif"));

JButton Blue6=new JButton(new ImageIcon("6x.gif"));

JButton Blue5=new JButton(new ImageIcon("5x.gif"));

JButton Blue4=new JButton(new ImageIcon("4x.gif"));

JButton Blue3=new JButton(new ImageIcon("3x.gif"));

JButton Blue2=new JButton(new ImageIcon("2x.gif"));

JButton Red9=new JButton(new ImageIcon("9s.gif"));

JButton Red8=new JButton(new ImageIcon("8s.gif"));

JButton Red7=new JButton(new ImageIcon("7s.gif"));

JButton Red6=new JButton(new ImageIcon("6s.gif"));

JButton Red5=new JButton(new ImageIcon("5s.gif"));

JButton Red4=new JButton(new ImageIcon("4s.gif"));

JButton Red3=new JButton(new ImageIcon("3s.gif"));

JButton Red2=new JButton(new ImageIcon("2s.gif"));

JButton Red1=new JButton(new ImageIcon("1s.gif"));

//电梯门定义

JButton LLiftLDoor=new JButton(new ImageIcon("LLiftLDoor.gif"));//设置门图标

JButton LLiftRDoor=new JButton(new ImageIcon("LLiftRDoor.gif"));//设置门图标

JButton RLiftLDoor=new JButton(new ImageIcon("RLiftLDoor.gif"));//设置门图标

JButton RLiftRDoor=new JButton(new ImageIcon("RLiftRDoor.gif"));//设置门图

相关文档
最新文档