Action Listener Update fuer BoardDisplay

This commit is contained in:
Kaver 2024-12-15 14:51:40 +01:00
parent 5be3f4daf3
commit 7605646b80
1 changed files with 17 additions and 2 deletions

View File

@ -80,13 +80,27 @@ public class BoardDisplay extends JPanel {
// }
// });
field.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
if (currentShip != null) {
previewShipPlacement(x, y, horizontal);
}
}
@Override
public void mouseExited(MouseEvent e) {
if (currentShip != null) {
clearPreview();
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
togglePlacementDirection(); // Ausrichtung ändern
togglePlacementDirection();
} else if (SwingUtilities.isLeftMouseButton(e)) {
Point o = new Point(x, y);
handleFieldClick(o); // Linksklick -> Schiff platzieren
currentShip.setHorizontal(horizontal);
}
}
});
@ -181,6 +195,7 @@ public class BoardDisplay extends JPanel {
}
public void refresh() {
paintFields();
}