📄 lift.java
字号:
package a;
import java.awt.*;
import javax.swing.*;
public class Lift extends JPanel {
Timer gateTimer,cageTimer;
boolean ifOpen;
final int GOUP =1,GODOWN =-1,FREE =0;
int state,floor;
int toppestCall,lowestCall;
int numOfFloor;
int[] upStop,downStop,stop;
int PanelWidth,PanelHeight,tagWidth,tagHeight,liftWidth,liftHeight,innerBtnWidth,innerBtnHeight;
int stateHeight, stateWidth;
InnerButton innerBtn;
LiftState liftState;
LiftCage cage;
Tag tag;
public Lift(int numOfFloor) {
setBackground(Color.lightGray);
init(numOfFloor);
innerBtn=new InnerButton(numOfFloor);
liftState = new LiftState();
cage=new LiftCage(numOfFloor);
tag=new Tag(numOfFloor);
setLayout(null);
tag.setBounds(liftWidth+9,3,tagWidth, tagHeight);
cage.setBounds(8, 3 ,liftWidth, liftHeight);
//innerBtn.setBounds(5+tagWidth+liftWidth,liftHeight-innerBtnHeight-90,innerBtnWidth,innerBtnHeight);
innerBtn.setBounds(10+tagWidth+liftWidth,5,innerBtnWidth,innerBtnHeight);
liftState.setBounds(10+tagWidth+liftWidth, 30+innerBtnHeight, stateWidth, stateHeight);
add(tag);
add(cage);
add(innerBtn);
add(liftState);
}
void init(int numOfFloor){
this.numOfFloor=numOfFloor;
ifOpen=false;
state=FREE;
floor=1;
toppestCall=numOfFloor+1;
lowestCall=0;
upStop=new int[numOfFloor+1];
downStop=new int[numOfFloor+1];
for(int i=1;i<=numOfFloor;i++)
upStop[i]= downStop[i]=0;
stop=new int[numOfFloor+1];
for(int i=1;i<=numOfFloor;i++)
stop[i]=0;
liftWidth=70;
liftHeight=60*numOfFloor;
tagWidth=30;
tagHeight=liftHeight;
innerBtnWidth=120;
innerBtnHeight=liftHeight/3;
stateWidth = 120;
stateHeight = 2 * liftHeight / 9;
PanelWidth=tagWidth+innerBtnWidth+liftWidth;
PanelHeight=liftHeight+10;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -