programmieren-projekt/src/ShipButton.java

44 lines
1.2 KiB
Java

import javax.swing.*;
import java.awt.*;
/**
* Das ShipButton Panel dient dem Erstellen eines lokalen Spiels.
* Hier kann der Benutzer Spieler inklusive Namen und das Semester, in dem sich der Benutzer befindet, einstellen.
* @author Lucas Bronson, Luca Conte, Joshua Kuklok
*/
public class ShipButton extends JButton {
private Ship ship;
private BoardDisplay boardDisplay;
/**
* TODO fertig beschreiben
* @param ship
* @param boardDisplay
* @author Lucas Bronson, Luca Conte, Joshua Kuklok
*/
public ShipButton(Ship ship, BoardDisplay boardDisplay) {
super(ship.getName());
this.ship = ship;
this.boardDisplay = boardDisplay;
this.addActionListener((e) -> {
boardDisplay.selectCurrentShip(this.ship);
});
}
/**
* Setzt Farbe der Modulbuttons.
* Verschiedene Farben für:
* Modul ausgewählt, platziert nicht platziert.
* @author Joshua Kuklok
*/
public void refreshButtonState() {
if (ship.isPlaced()) {
setBackground(Color.LIGHT_GRAY);
} else {
setBackground(Color.WHITE);
}
if (boardDisplay.getCurrentShip() == ship) {
setBackground(Color.CYAN);
}
}
}