44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
package gui;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.event.*;
|
|
|
|
import commandSystem.ElevatorListener;
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
class ElevatorPanel extends JPanel {
|
|
private JButton emergencyStop = new JButton("Emergency stop.");
|
|
private JButton cancelEmergencyStop = new JButton("Cancel emergency stop.");
|
|
private JButton[] buttons;
|
|
|
|
public ElevatorPanel(int nbFloors, ElevatorListener l) {
|
|
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
|
this.add(new JLabel("Elevator panel."));
|
|
|
|
buttons = new JButton[nbFloors];
|
|
for (int i = nbFloors-1; i >= 0; i--) {
|
|
final int j = i;
|
|
buttons[i] = new JButton("" + i);
|
|
buttons[i].addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
l.elevatorCall(j);
|
|
}
|
|
});
|
|
this.add(buttons[i]);
|
|
}
|
|
emergencyStop.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
l.emergency();
|
|
}
|
|
});
|
|
add(emergencyStop);
|
|
cancelEmergencyStop.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
l.cancelEmergency();
|
|
}
|
|
});
|
|
add(cancelEmergencyStop);
|
|
}
|
|
}
|