Compare commits
No commits in common. "864419c22e780fef8df3739f9659bc4ad65361b3" and "27c2ffefaabd5a8065fe42dbb62ebaf3b660003d" have entirely different histories.
864419c22e
...
27c2ffefaa
@ -48,7 +48,7 @@ public class ElevatorApplication implements ActionListener {
|
|||||||
|
|
||||||
pane.add(Box.createRigidArea(new Dimension(20, 0)));
|
pane.add(Box.createRigidArea(new Dimension(20, 0)));
|
||||||
|
|
||||||
ElevatorPanel elevatorPanel = new ElevatorPanel(5, simulation);
|
ElevatorPanel elevatorPanel = new ElevatorPanel(5);
|
||||||
elevatorPanel.setAlignmentY(Component.TOP_ALIGNMENT);
|
elevatorPanel.setAlignmentY(Component.TOP_ALIGNMENT);
|
||||||
pane.add(elevatorPanel);
|
pane.add(elevatorPanel);
|
||||||
|
|
||||||
|
@ -1,29 +1,20 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
import commandSystem.ElevatorListener;
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class ElevatorPanel extends JPanel {
|
class ElevatorPanel extends JPanel {
|
||||||
private JButton emergencyStop = new JButton("Emergency stop.");
|
private JButton emergencyStop = new JButton("Emergency stop.");
|
||||||
private JButton[] buttons;
|
private JButton[] buttons;
|
||||||
|
|
||||||
public ElevatorPanel(int nbFloors, ElevatorListener l) {
|
public ElevatorPanel(int nbFloors) {
|
||||||
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
||||||
this.add(new JLabel("Elevator panel."));
|
this.add(new JLabel("Elevator panel."));
|
||||||
|
|
||||||
buttons = new JButton[nbFloors];
|
buttons = new JButton[nbFloors];
|
||||||
for (int i = nbFloors-1; i >= 0; i--) {
|
for (int i = nbFloors-1; i >= 0; i--) {
|
||||||
final int j = i;
|
|
||||||
buttons[i] = new JButton("" + i);
|
buttons[i] = new JButton("" + i);
|
||||||
buttons[i].addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
l.elevatorCall(j);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.add(buttons[i]);
|
this.add(buttons[i]);
|
||||||
}
|
}
|
||||||
add(emergencyStop);
|
add(emergencyStop);
|
||||||
|
@ -5,7 +5,6 @@ import java.awt.*;
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
import commandSystem.ElevatorListener;
|
import commandSystem.ElevatorListener;
|
||||||
import commandSystem.Direction;
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@ -23,23 +22,11 @@ class FloorPanels extends JPanel {
|
|||||||
floors[i].setLayout(new BoxLayout(floors[i], BoxLayout.LINE_AXIS));
|
floors[i].setLayout(new BoxLayout(floors[i], BoxLayout.LINE_AXIS));
|
||||||
floors[i].add(new JLabel("" + i));
|
floors[i].add(new JLabel("" + i));
|
||||||
if (i < nbFloors - 1) {
|
if (i < nbFloors - 1) {
|
||||||
final int j = i;
|
|
||||||
JButton upButton = new JButton("↑");
|
JButton upButton = new JButton("↑");
|
||||||
upButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
l.floorCall(j, Direction.UP);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
floors[i].add(upButton);
|
floors[i].add(upButton);
|
||||||
}
|
}
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
final int j = i;
|
|
||||||
JButton downButton = new JButton("↓");
|
JButton downButton = new JButton("↓");
|
||||||
downButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
l.floorCall(j, Direction.DOWN);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
floors[i].add(downButton);
|
floors[i].add(downButton);
|
||||||
}
|
}
|
||||||
this.add(floors[i]);
|
this.add(floors[i]);
|
||||||
|
@ -20,11 +20,9 @@ public class Simulation implements ElevatorListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void elevatorCall(int floor) {
|
public void elevatorCall(int floor) {
|
||||||
System.out.println("elevator call " + floor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void floorCall(int floor, Direction direction) {
|
public void floorCall(int floor, Direction direction) {
|
||||||
System.out.println("floor call " + floor + " " + direction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void floorChange(Direction d) {
|
public void floorChange(Direction d) {
|
||||||
|
Reference in New Issue
Block a user