This repository has been archived on 2019-10-19. You can view files and clone it, but cannot push or open issues or pull requests.
projet-gl/src/gui/ElevatorApplication.java

70 lines
1.7 KiB
Java

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) {
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();
}
});
}
}