欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOCX文档下载  

    电梯模拟程序.docx

    • 资源ID:3663442       资源大小:43.13KB        全文页数:44页
    • 资源格式: DOCX        下载积分:6.99金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要6.99金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    电梯模拟程序.docx

    电梯模拟程序import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.*;public class LiftMainTestpublic static void main(String args)new LiftTest("电梯测试");/批量数据测试对话框class Dialog extends JDialog implements ActionListenerint Message=0;JPanel DJPanel=new JPanel;JTextField TestField=new JTextField16;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&lt=15;i+)TestFieldi=new JTextField(4);DJPanel.add(TestLabel1);DJPanel.add(TestLabel2);DJPanel.add(TestLabel3);DJPanel.add(TestLabel4);DJPanel.add(TestField0);DJPanel.add(TestField1);DJPanel.add(TestField2);DJPanel.add(TestField3);DJPanel.add(TestField4);DJPanel.add(TestField5);DJPanel.add(TestField6);DJPanel.add(TestField7);DJPanel.add(TestField8);DJPanel.add(TestField9);DJPanel.add(TestField10);DJPanel.add(TestField11);DJPanel.add(TestField12);DJPanel.add(TestField13);DJPanel.add(TestField14);DJPanel.add(TestField15);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;/左电梯是否在运行int RIsRun=0;/右电梯是否在运行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 int11;/保留数组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");/设置门图标/电梯内部按钮定义JButton LPressButton1=new JButton("1");JButton LPressButton2=new JButton("2");JButton LPressButton3=new JButton("3");JButton LPressButton4=new JButton("4");JButton LPressButton5=new JButton("5");JButton LPressButton6=new JButton("6");JButton LPressButton7=new JButton("7");JButton LPressButton8=new JButton("8");JButton LPressButton9=new JButton("9");JButton LPressButton10=new JButton("10");JButton RPressButton1=new JButton("1");JButton RPressButton2=new JButton("2");JButton RPressButton3=new JButton("3");JButton RPressButton4=new JButton("4");JButton RPressButton5=new JButton("5");JButton RPressButton6=new JButton("6");JButton RPressButton7=new JButton("7");JButton RPressButton8=new JButton("8");JButton RPressButton9=new JButton("9");JButton RPressButton10=new JButton("10");量数据测试”按钮的Panel/组件定义JLabel LL=new JLabel("当前电梯内部人数:");JLabel RL=new JLabel("当前电梯内部人数:");JButton Start=new JButton("开始电梯调度模拟");/开始电梯调度模拟按钮JButton Test=new JButton("开始批量数据测试");/开始批量数据测试按钮JTextArea LTextArea=new JTextArea(5,5);JTextArea RTextArea=new JTextArea(5,5);/电梯调度函数 Cal(LIsRun,LLiftNowLevel,q,LDirection)int Cal(int x,int y,int z,int w)return(x*(y-z)*w);/方法函数LiftTest(String s)super(s);setSize(1000,600);setLocation(100,50);/Dialogmydialog=new Dialog(this,"批量数据测试",true);/菜单项设置menubar=new JMenuBar;menu=new JMenu("菜单");submenu=new JMenu("联系作者");submenuhelp=new JMenu("帮助");item1=new JMenuItem("程序简介");item2=new JMenuItem("源代码");menu.add(item1);menu.addSeparator;menu.add(item2);menu.addSeparator;menu.add(submenu);menu.addSeparator;menu.add(submenuhelp);submenu.add(new JMenuItem("作者简介");submenuhelp.add(new JMenuItem("使用帮助");menubar.add(menu);setJMenuBar(menubar);/面板布局管理器设置WindowsPanel.setLayout(new GridLayout(1,6);WaitPeopleNumPanel.setLayout(new GridLayout(10,1);LeftPanel.setLayout(new GridLayout(3,1);RightPanel.setLayout(new GridLayout(3,1);LeftLiftPanel.setLayout(null);/左电梯运动轨道Panel布局管理器设为空RightLiftPanel.setLayout(null);/右电梯运动轨道Panel布局管理器设为空UpDownButtonPanel.setLayout(new GridLayout(10,2);LButtonPanel.setLayout(new GridLayout(4,3);RButtonPanel.setLayout(new GridLayout(4,3);LeftLiftPanel.setBackground(Color.green);RightLiftPanel.setBackground(Color.green);UpDownButtonPanel.setBackground(Color.yellow);UpMainPanel.setLayout(new GridLayout(1,2);LBoxPanel.setLayout(null);/左电梯箱Panel布局管理器设为空RBoxPanel.setLayout(null);/右电梯箱Panel布局管理器设为空/电梯箱设置LBoxPanel.setSize(165,51);RBoxPanel.setSize(165,51);LBoxPanel.setLocation(0,459);RBoxPanel.setLocation(0,459);LeftLiftPanel.add(LBoxPanel);RightLiftPanel.add(RBoxPanel);/电梯门设置LLiftLDoor.setEnabled(false);LLiftRDoor.setEnabled(false);RLiftLDoor.setEnabled(false);RLiftRDoor.setEnabled(false);LLiftLDoor.setSize(82,51);LLiftRDoor.setSize(82,51);RLiftLDoor.setSize(82,51);RLiftRDoor.setSize(82,51);LLiftLDoor.setLocation(0,0);LLiftRDoor.setLocation(82,0);RLiftLDoor.setLocation(0,0);RLiftRDoor.setLocation(82,0);LBoxPanel.add(LLiftLDoor);LBoxPanel.add(LLiftRDoor);RBoxPanel.add(RLiftLDoor);RBoxPanel.add(RLiftRDoor);/分别添加两个电梯的10个按钮LButtonPanel.add(LPressButton1);/左电梯LButtonPanel.add(LPressButton2);LButtonPanel.add(LPressButton3);LButtonPanel.add(LPressButton4);LButtonPanel.add(LPressButton5);LButtonPanel.add(LPressButton6);LButtonPanel.add(LPressButton7);LButtonPanel.add(LPressButton8);LButtonPanel.add(LPressButton9);LButtonPanel.add(LPressButton10); RButtonPanel.add(RPressButton1);/右电梯RButtonPanel.add(RPressButton2);RButtonPanel.add(RPressButton3);RButtonPanel.add(RPressButton4);RButtonPanel.add(RPressButton5);RButtonPanel.add(RPressButton6);RButtonPanel.add(RPressButton7);RButtonPanel.add(RPressButton8);RButtonPanel.add(RPressButton9);RButtonPanel.add(RPressButton10);/添加上下电梯按钮至UpDownButtonPanel面板JButton Unabled1=new JButton;Unabled1.setEnabled(false);JButton Unabled2=new JButton;Unabled2.setEnabled(false);UpDownButtonPanel.add(Unabled1);/开始第一个空着UpDownButtonPanel.add(Blue10);UpDownButtonPanel.add(Red9);UpDownButtonPanel.add(Blue9);UpDownButtonPanel.add(Red8);UpDownButtonPanel.add(Blue8);UpDownButtonPanel.add(Red7);UpDownButtonPanel.add(Blue7);UpDownButtonPanel.add(Red6);UpDownButtonPanel.add(Blue6);UpDownButtonPanel.add(Red5);UpDownButtonPanel.add(Blue5);UpDownButtonPanel.add(Red4);UpDownButtonPanel.add(Blue4);UpDownButtonPanel.add(Red3);UpDownButtonPanel.add(Blue3);UpDownButtonPanel.add(Red2);UpDownButtonPanel.add(Blue2);UpDownButtonPanel.add(Red1);UpDownButtonPanel.add(Unabled2);/最后一个空着/等待人数文本框定义JTextField Text10=new JTextField(" 10楼等待人数:",8);Text10.setEditable(false);JTextField Text9=new JTextField(" 9楼等待人数:",8);Text9.setEditable(false);JTextField Text8=new JTextField(" 8楼等待人数:",8);Text8.setEditable(false);JTextField Text7=new JTextField(" 7楼等待人数:",8);Text7.setEditable(false);JTextField Text6=new JTextField(" 6楼等待人数:",8);Text6.setEditable(false);JTextField Text5=new JTextField(" 5楼等待人数:",8);Text5.setEditable(false);JTextField Text4=new JTextField(" 4楼等待人数:",8);Text4.setEditable(false);JTextField Text3=new JTextField(" 3楼等待人数:",8);Text3.setEditable(false);JTextField Text2=new JTextField(" 2楼等待人数:",8);Text2.setEditable(false);JTextField Text1=new JTextField(" 1楼等待人数:",8);Text1.setEditable(false);/向UpMainPanel中添加组件UpMainPanel.add(Start);UpMainPanel.add(Test);/添加等待人数文本框至WaitPeopleNumPanel面板WaitPeopleNumPanel.add(Text10);WaitPeopleNumPanel.add(Text9);WaitPeopleNumPanel.add(Text8);WaitPeopleNumPanel.add(Text7);WaitPeopleNumPanel.add(Text6);WaitPeopleNumPanel.add(Text5);WaitPeopleNumPanel.add(Text4);WaitPeopleNumPanel.add(Text3);WaitPeopleNumPanel.add(Text2);WaitPeopleNumPanel.add(Text1);/分别向LeftPanel(左电梯提示器),RightPanel(右电梯提示器)添加相应组件LeftPanel.add(LButtonPanel);LeftPanel.add(LL);LeftPanel.add(LTextArea);RightPanel.add(RButtonPanel);RightPanel.add(RL);RightPanel.add(RTextArea);/添加至总面板WindowsPanel.add(WaitPeopleNumPanel);WindowsPanel.add(LeftPanel);WindowsPanel.add(LeftLiftPanel);WindowsPanel.add(UpDownButtonPanel);WindowsPanel.add(RightLiftPanel);WindowsPanel.add(RightPanel);/添加监听器Start.addActionListener(this);Test.addActionListener(this);Blue10.addActionListener(this);Blue9.addActionListener(this);Blue8.addActionListener(this);Blue7.addActionListener(this);Blue6.addActionListener(this);Blue5.addActionListener(this);Blue4.addActionListener(this);Blue3.addActionListener(this);Blue2.addActionListener(this);Red9.addActionListener(this);Red8.addActionListener(this);Red7.addActionListener(this);Red6.addActionListener(this);Red5.addActionListener(this);Red4.addActionListener(this);Red3.addActionListener(this);Red2.addActionListener(this);Red1.addActionListener(this);Monitor mon=new Monitor;/新建监听器对象LPressButton1.addActionListener(mon);LPressButton2.addActionListener(mon);LPressButton3.addActionListener(mon);LPressButton4.addActionListener(mon);LPressButton5.addActionListener(mon);LPressButton6.addActionListener(mon);LPressButton7.addActionListener(mon);LPressButton8.addActionListener(mon);LPressButton9.addActionListener(mon);LPressButton10.addActionListener(mon);RPressButton1.addActionListener(mon);RPressButton2.addActionListener(mon);RPressButton3.addActionListener(mon);RPressButton4.addActionListener(mon);RPressButton5.addActionListener(mon);RPressButton6.addActionListener(mon);RPressButton7.addActionListener(mon);RPressButton8.addActionListener(mon);RPressButton9.addActionListener(mon);RPressButton10.addActionListener(mon);/添加至窗口add(WindowsPanel,BorderLayout.CENTER);/主窗体添加至中间add(UpMainPanel,BorderLayout.NORTH);/UpMainPanel添加至北面setVisible(true);/Frame默认是不可见的,所有Panel都是默认可见的validate;/设置组件可见setResizable(false);/设置整个窗体是不可调整大小的setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/右上角“叉号”关闭按钮响应函数 /Runnable接口函数定义class LIO implements Runnable/左电梯接口函数public void runwhile(true)tryThread.sleep(5);/避免CPU使用率达到100%catch(InterruptedException a)while(LNowLevel!=0)int q=x;if(Cal(LIsRun,LLiftNowLevel,q,LDirection)&lt=Cal(RIsRun,RLiftNowLevel,q,RDirection)/左电梯近LNowLevel=0;if(LLiftNowLevel&lt=q)for(int i=LLiftNowLevel;i&ltq;i+)LBoxPanel.setLocation(0,(459-i*51);LTextArea.append("妹妹n");RTextArea.append("哥哥n");LLiftNowLevel=i;LIsRun=1;LDirection=1;if(LNowLevel!=0&&i=(LNowLevel-1)&&LDirection=1&&WantDirection=1)/停留等待4秒for(int v=1;v&lt=82;v+)/开门tryThread.sleep(49);catch(InterruptedException a)LLiftLDoor.setLocation(-v),0);LLiftRDoor.setLocation(82+v),0);tryThread.sleep(4000);catch(InterruptedException a)for(int v=1;v&lt=82;v+)/关门tryThread.sleep(49);catch(InterruptedException a)LLiftLDoor.setLocation(v-82),0);LLiftRDoor.setLocation(163-v),0);tryThread.sleep(1000);catch(InterruptedException a) elsefor(int i=LLiftNowLevel;i&gtq;i-)LBoxPanel.setLocation(0,(459-(i-2)*51);LTextArea.append("妹妹");RTextArea.append("哥哥");LLiftNowLevel=i;LIsRun=1;LDirection=-1;if(LNowLevel!=0&&i=(LNowLevel+1)&&LDirection=-1&&WantDirection=-1)/停留等待4秒for(int v=1;v&lt=82;v+)/开门tryThread.sleep(49);catch(InterruptedException a)LLiftLDoor.setLocation(-v),0);LLiftRDoor.setLocation(82+v),0);tryThread.sleep(4000);catch(InterruptedException a)for(int v=1;v&lt=82;v+)/关门tryThread.sleep(49);catch(InterruptedException a)LLiftLDoor.setLocation(v-82),0);LLiftRDoor.setLocation(163-v),0); tryThread.sleep(1000);catch(InterruptedException a)LIsRun=0;LDirection=0;LLiftNowLevel=q; elsebreak;for(int e=1;e&lt=82;e+)/开门if(a=1)/识别用户按下电梯箱内小按钮x=LWantLevel;LNowLevel=LWantLevel;a=0;/"a"值复位tryThread.sleep(49);catch(InterruptedException a)LLiftLDoor.setLocation(-e),0);LLiftRDoor.setLocation(82+e),0);for(int e=1;e&lt=82;e+)if(a=1)/识别用户按下电梯箱内小按钮x=LWantLevel;LNowLevel=LWantLevel;a=0;/"a"值复位tryThread.sleep(49);catch(InterruptedException a)for(int e=1;e&lt=82;e+)/关门if(a=1)/识别用户按下电梯箱内小按钮x=LWantLevel;LNowLevel=LWantLevel;a=0;/"a"值复位tryThread.sleep(49);catch(InterruptedException a)LLiftLDoor.setLocation(e-82),0);LLiftRDoor.setLocation(163-e),0); class RIO implements Runnable/右电梯接口函数public void runwhile(true)tryThread.sleep(5);catch(InterruptedException a)while(RNowLevel!=0)int p=y;if(Cal(LIsRun,LLiftNowLevel,p,LDirection)&gt=Cal(RIsRun,RLiftNowLevel,p,RDirection)/右电梯近RNowLevel=0;if(RLiftNowLevel&lt=p)for(int i=RLiftNowLevel;i&ltp;i+)RBoxPanel.setLocation(0,(459-i*51);LTextArea.append("妹妹n");RTextArea.append("哥哥n");RLiftNowLevel=i;RIsRun=1;RDirection=1;if(RNowLevel!=0&&i=(RNowLevel-1)&&RDirection=1&&WantDirection=1)/停留等待4秒for(int v=1;v&lt=82;v+)tryThread.sleep(49);catch(InterruptedException a)RLiftLDoor.setLocation(-v),0);RLiftRDoor.setLocation(82+v),0);tryThread.sleep(4000);catch(InterruptedException a)for(int v=1;v&lt=82;v+)tryThread.sleep(49);

    注意事项

    本文(电梯模拟程序.docx)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开