资源简介
多电梯联控模拟-JAVA实现,适合初学者,5台20层多电梯联控模拟,采用逻辑公平性的算法。
代码片段和文件信息
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
//import OneElevator.AnalysisThread;
public class ElevatorInitial extends Jframe implements ActionListener{
final int Uping = 1;
final int Downing = -1;
final int Stoping = 0;
boolean MulEle =true;
OneElevator[] Elevator = new OneElevator[5];
JPanel Elevators = new JPanel(new FlowLayout(FlowLayout.CENTER101));
JButton MulOrSin = new JButton(“Muti <=> Sin“);
ExecutorService executorFindElevator = Executors.newFixedThreadPool(20);
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable(){
public synchronized void run(){
ElevatorInitial ElevatorInterface = new ElevatorInitial();
ElevatorInterface.setVisible(true);
}
});
}
public ElevatorInitial(){
this.setResizable(false);
this.setBounds(0 0 1360 730);
this.setLayout(new FlowLayout(FlowLayout.LEFT00));
for(int i=0; i<5; i++){
Elevator[i] = new OneElevator();
Elevators.add(Elevator[i]);
if( i != 0 ){
if(MulEle == true){
for(int j = 0; j<20;j++)
Elevator[i].Floor[j].updownControl.setVisible(false);
}
}
}
MulOrSin.setSize(20 50);
MulOrSin.setBackground(new Color(235 235 235));
//Color InitialBColor = new Color(235 235 235);
Elevators.add(MulOrSin);
this.add(Elevators);
for(int tempforEle = 0; tempforEle<5;tempforEle++){
for( int tempforUDB = 0; tempforUDB < 20; tempforUDB++ ){ //adding up down button
if(tempforEle == 0 ){
Elevator[tempforEle].Floor[tempforUDB].upButton.addActionListener(this);
Elevator[tempforEle].Floor[tempforUDB].downButton.addActionListener(this);
}
else{
Elevator[tempforEle].Floor[tempforUDB].upButton.addActionListener(Elevator[tempforEle]);
Elevator[tempforEle].Floor[tempforUDB].downButton.addActionListener(Elevator[tempforEle]);
}
}
}
MulOrSin.addActionListener(this);
}
class ElevatorChooser implements Runnable{
int targetfloor;
int DirectionWanted;
String LockFindElevator = new String();
int Distance[] = new int[5]; // store the distance betweenn tf and the every elevator
int NearestDistance = 10000; //infinite to let it equals the first;
int FirstChoice = 0; // the final elevator to input the targetfloor
//for the request from inside
public ElevatorChooser(){
}
//for the request from outside
public ElevatorChooser(int tf int sign){
targetfloor = tf;
DirectionWanted = sign;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-05-12 21:27 Elevator-ALL\
文件 28888 2015-05-12 21:25 Elevator-ALL\Elevator-scheduler.jar
文件 660535 2015-05-11 00:06 Elevator-ALL\ElevatorInitial-CODE.png
文件 141985 2015-05-11 00:08 Elevator-ALL\InsideControlBoard-CODE.png
文件 6047289 2015-05-11 00:01 Elevator-ALL\MULTI-Elevator-PRE.wmv
文件 1276792 2015-05-11 00:10 Elevator-ALL\OneElevator-code.png
文件 661308 2015-05-11 00:12 Elevator-ALL\OneFloor-CODE.png
目录 0 2015-05-12 20:59 Elevator-ALL\Source Code\
文件 9482 2015-05-08 22:22 Elevator-ALL\Source Code\ElevatorInitial.java
文件 2285 2015-04-28 12:26 Elevator-ALL\Source Code\InsideControlBoard.java
文件 20422 2015-05-08 22:18 Elevator-ALL\Source Code\OneElevator.java
文件 10329 2015-05-08 22:21 Elevator-ALL\Source Code\OneFloor.java
- 上一篇:《Design Patterns》中文版
- 下一篇:Java技术手册第6版 pdf
评论
共有 条评论