电梯模拟程序.docx
《电梯模拟程序.docx》由会员分享,可在线阅读,更多相关《电梯模拟程序.docx(44页珍藏版)》请在三一办公上搜索。
1、电梯模拟程序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 JText
2、Field16;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;
3、i<=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(TestFiel
4、d6);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
5、);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 mydialo
6、g;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;/
7、左电梯目前所在层数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=
8、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(
9、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.
10、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
11、 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 LPres
12、sButton4=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 RPressB
13、utton2=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 RPressButto
14、n10=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,LLiftNo
15、wLevel,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
16、(程序简介);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(ne
17、w 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)
18、;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布局管理器设
19、为空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.setE
20、nabled(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
21、(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(LPressB
22、utton7);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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 电梯 模拟 程序
链接地址:https://www.31ppt.com/p-3663442.html