diff --git a/src/gui/ElevatorApplication.java b/src/gui/ElevatorApplication.java index f920a02..1ce9bf4 100644 --- a/src/gui/ElevatorApplication.java +++ b/src/gui/ElevatorApplication.java @@ -1,11 +1,25 @@ package gui; + import javax.swing.*; import java.awt.*; import java.awt.event.*; +import Requests.CallFromElevatorRequest; +import Requests.CallFromFloorRequest; +import simulation.Elevator; +import simulation.Simulation; + public class ElevatorApplication implements ActionListener { private ElevatorCanvas canvas; + private Simulation simulation; + private Elevator elevator; + + public ElevatorApplication() { + elevator = new Elevator(0, 5); + simulation = new Simulation(elevator); + elevator.setActionListener(simulation); + } @Override public void actionPerformed(ActionEvent e) { @@ -21,7 +35,7 @@ public class ElevatorApplication implements ActionListener { pane.add(Box.createHorizontalGlue()); - canvas = new ElevatorCanvas(); + canvas = new ElevatorCanvas(elevator); canvas.setAlignmentY(Component.TOP_ALIGNMENT); pane.add(canvas); @@ -43,6 +57,7 @@ public class ElevatorApplication implements ActionListener { public static void main(String[] args) { ElevatorApplication app = new ElevatorApplication(); + SwingUtilities.invokeLater(new Runnable() { public void run() { app.createAndShowGUI(); diff --git a/src/gui/ElevatorCanvas.java b/src/gui/ElevatorCanvas.java index d4065cc..0a16215 100644 --- a/src/gui/ElevatorCanvas.java +++ b/src/gui/ElevatorCanvas.java @@ -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); }