52 lines
1.4 KiB
Java
52 lines
1.4 KiB
Java
package gui;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
|
|
import commandSystem.ElevatorListener;
|
|
import commandSystem.Direction;
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
class FloorPanels extends JPanel {
|
|
private int nbFloors;
|
|
private JPanel[] floors;
|
|
|
|
public FloorPanels(int nbFloors, ElevatorListener l) {
|
|
this.nbFloors = nbFloors;
|
|
floors = new JPanel[nbFloors];
|
|
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
|
this.add(new JLabel("Call."));
|
|
for (int i = nbFloors-1; i >= 0; i--) {
|
|
floors[i] = new JPanel();
|
|
floors[i].setLayout(new BoxLayout(floors[i], BoxLayout.LINE_AXIS));
|
|
floors[i].add(new JLabel("" + i));
|
|
floors[i].add(Box.createRigidArea(new Dimension(5, 0)));
|
|
if (i < nbFloors - 1) {
|
|
final int j = i;
|
|
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(Box.createRigidArea(new Dimension(5, 0)));
|
|
}
|
|
if (i > 0) {
|
|
final int j = i;
|
|
JButton downButton = new JButton("↓");
|
|
downButton.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
l.floorCall(j, Direction.DOWN);
|
|
}
|
|
});
|
|
floors[i].add(downButton);
|
|
}
|
|
this.add(floors[i]);
|
|
this.add(Box.createRigidArea(new Dimension(0, 5)));
|
|
}
|
|
}
|
|
}
|