make ElevatorCanvas reflect the state of the Elevator
This commit is contained in:
@ -1,15 +1,22 @@
|
||||
package gui;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import simulation.Elevator;
|
||||
import commandSystem.Direction;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class ElevatorCanvas extends JPanel {
|
||||
private final static int WIDTH = 40;
|
||||
private final static int HEIGHT = 50;
|
||||
private final static Color COLOR = Color.PINK;
|
||||
private final static Dimension DIMENSIONS = new Dimension(WIDTH, 200);
|
||||
|
||||
private int y = 0;
|
||||
private Elevator elevator;
|
||||
|
||||
public ElevatorCanvas(Elevator elevator) {
|
||||
this.elevator = elevator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getMinimumSize() {
|
||||
@ -27,7 +34,18 @@ class ElevatorCanvas extends JPanel {
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(COLOR);
|
||||
if (elevator.getStoppingNextFloor()) {
|
||||
g.setColor(Color.BLUE);
|
||||
}
|
||||
else if (elevator.getDirection() == Direction.NONE) {
|
||||
g.setColor(Color.GRAY);
|
||||
}
|
||||
else if (elevator.getEmergency()) {
|
||||
g.setColor(Color.RED);
|
||||
}
|
||||
else {
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
g.fillRect(0, y, WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user