📄 outframe.java
字号:
package userClient;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import Data.*;
import Extend.*;
@SuppressWarnings("serial")
public class OutFrame extends JFrame implements ActionListener, WindowListener{
XYClient OutFramexy;
Person ppp;
StateData outFrameAllDate;
int upbutton = 0;//1代表灯开着
int downbutton = 0;
HelpCenter touchScreen;
private JButton floor = new JButton();
private JPanel panelNorth = new JPanel();
DoorPanel doorA;
DoorPanel doorB;
DoorPanel doorC;
DoorPanel doorD;
private JButton upOne = new JButton();//左上
private JButton upTwo= new JButton();//右上
private JButton downOne = new JButton();//左下
private JButton downTwo = new JButton();//右下
private JPanel panelCenter = new JPanel();
public void setOutFloor(int onWhichFloor) {
floor.setFont(new Font("", Font.BOLD,50));
floor.setBackground(Color.LIGHT_GRAY);
floor.setForeground(Color.RED);
floor.setText(onWhichFloor + "");
repaint();
}
public int getUpButton() {
return upbutton;
}
public int getDownButton() {
return downbutton;
}
public void setUpButton(int upbutton) {
if (upbutton == 1) {
upOne.setEnabled(false);
upTwo.setEnabled(false);
}
else {
upOne.setEnabled(true);
upTwo.setEnabled(true);
}
repaint();
}
public void setDownButton(int downbutton){
if(downbutton == 1){
downOne.setEnabled(false);
downTwo.setEnabled(false);
}
else {
downOne.setEnabled(true);
downTwo.setEnabled(true);
}
repaint();
}
//需要修改,以便实现help center
public void actionPerformed(ActionEvent e) {
if (e.getSource() == touchScreen.button[1]) {
if (ppp.getOnWhichFloor() > 1) {
sendDownRequest();
}else {
//扫尾
}
}else if (e.getSource() == touchScreen.button[2]) {
if (ppp.getOnWhichFloor() > 2) {
sendDownRequest();
}else if (ppp.getOnWhichFloor() < 2){
sendUpRequest();
}else {
//扫尾
}
}else if (e.getSource() == touchScreen.button[3]) {
if (ppp.getOnWhichFloor() > 3) {
sendDownRequest();
}else if (ppp.getOnWhichFloor() < 3){
sendUpRequest();
}else {
//扫尾
}
}else if (e.getSource() == touchScreen.button[4]) {
if (ppp.getOnWhichFloor() > 4) {
sendDownRequest();
}else if (ppp.getOnWhichFloor() < 4){
sendUpRequest();
}else {
//扫尾
}
}else if (e.getSource() == touchScreen.button[5]) {
if (ppp.getOnWhichFloor() > 5) {
sendDownRequest();
}else if (ppp.getOnWhichFloor() < 5){
sendUpRequest();
}else {
//扫尾
}
}else if (e.getSource() == touchScreen.button[6]) {
if (ppp.getOnWhichFloor() > 6) {
sendDownRequest();
}else if (ppp.getOnWhichFloor() < 6){
sendUpRequest();
}else {
//扫尾
}
}else if (e.getSource() == touchScreen.button[7]) {
if (ppp.getOnWhichFloor() > 7) {
sendDownRequest();
}else if (ppp.getOnWhichFloor() < 7){
sendUpRequest();
}else {
//扫尾
}
}else if (e.getSource() == touchScreen.button[8]) {
if (ppp.getOnWhichFloor() > 8) {
sendDownRequest();
}else if (ppp.getOnWhichFloor() < 8){
sendUpRequest();
}else {
//扫尾
}
}else if (e.getSource() == touchScreen.button[9]) {
if (ppp.getOnWhichFloor() > 9) {
sendDownRequest();
}else if (ppp.getOnWhichFloor() < 9){
sendUpRequest();
}else {
//扫尾
}
}else if (e.getSource() == touchScreen.button[10]) {
if (ppp.getOnWhichFloor() < 10){
sendUpRequest();
}else {
//扫尾
}
}else {
//扫尾工作
}
}
//修改原先的向下请求,成为子函数
public void sendDownRequest() {
downbutton = 1;
ppp.setGo(-1);
OuterPassengerCommandData a = new OuterPassengerCommandData();
a.button = -1;
a.floor = ppp.getOnWhichFloor();
OutFramexy.SendOuterData(a);
}
//修改原先的向上请求,成为子函数
public void sendUpRequest() {
upbutton = 1;
ppp.setGo(1);
OuterPassengerCommandData a = new OuterPassengerCommandData();
a.button = 1;
a.floor = ppp.getOnWhichFloor();
OutFramexy.SendOuterData(a);
}
public OutFrame(Person ppp,XYClient OutFramexy,int onWhichFloor,
int upbutton, int downbutton,StateData outFrameAllDate) {
touchScreen = new HelpCenter();//这里是Help Center
this.ppp = ppp;
this.OutFramexy = OutFramexy;
this.outFrameAllDate = outFrameAllDate;
setOutFloor(onWhichFloor);
setUpButton(upbutton);
setDownButton(downbutton);
doorA = new DoorPanel(1,outFrameAllDate.elevator[0].direction,outFrameAllDate.elevator[0].floor,ppp,OutFramexy);
doorB = new DoorPanel(2,outFrameAllDate.elevator[1].direction,outFrameAllDate.elevator[1].floor,ppp,OutFramexy);
doorC = new DoorPanel(3,outFrameAllDate.elevator[2].direction,outFrameAllDate.elevator[2].floor,ppp,OutFramexy);
doorD = new DoorPanel(4,outFrameAllDate.elevator[3].direction,outFrameAllDate.elevator[3].floor,ppp,OutFramexy);
panelNorth.add(floor);
panelNorth.setBackground(Color.LIGHT_GRAY);
//增加Help Center监听
for (int i = 1; i <= 10; i++) {
touchScreen.button[i].addActionListener(this);
}
panelCenter.setBackground(Color.LIGHT_GRAY);
panelCenter.setLayout(new GridLayout(1,5));
panelCenter.add(doorA);
panelCenter.add(doorB);
panelCenter.add(touchScreen);
panelCenter.add(doorC);
panelCenter.add(doorD);
setBackground(Color.LIGHT_GRAY);
setLayout(new BorderLayout());
add(panelNorth, BorderLayout.NORTH);
add(panelCenter, BorderLayout.CENTER);
addWindowListener(this);
touchScreen.setMessage("!");
}
public void windowDeactivated(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowClosed(WindowEvent e){
}
public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
OutFramexy.Close();
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -