package gui; import java.awt.*; import java.awt.event.*; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.Timer; 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) { canvas.setElevatorY((canvas.getElevatorY() + 1) % canvas.getHeight()); } private void createAndShowGUI() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = frame.getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.LINE_AXIS)); pane.add(Box.createHorizontalGlue()); canvas = new ElevatorCanvas(elevator); canvas.setAlignmentY(Component.TOP_ALIGNMENT); pane.add(canvas); FloorPanels fp = new FloorPanels(5, simulation); fp.setAlignmentY(Component.TOP_ALIGNMENT); pane.add(fp); pane.add(Box.createRigidArea(new Dimension(20, 0))); ElevatorPanel elevatorPanel = new ElevatorPanel(5); elevatorPanel.setAlignmentY(Component.TOP_ALIGNMENT); pane.add(elevatorPanel); pane.add(Box.createHorizontalGlue()); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { ElevatorApplication app = new ElevatorApplication(); SwingUtilities.invokeLater(new Runnable() { public void run() { app.createAndShowGUI(); Timer t = new Timer(16, app); t.start(); } }); } }