From 7605646b80107b5da9272c86cffef0d29f486976 Mon Sep 17 00:00:00 2001 From: Kaver Date: Sun, 15 Dec 2024 14:51:40 +0100 Subject: [PATCH] Action Listener Update fuer BoardDisplay --- src/BoardDisplay.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/BoardDisplay.java b/src/BoardDisplay.java index 7d10ab1..d06563c 100644 --- a/src/BoardDisplay.java +++ b/src/BoardDisplay.java @@ -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(); }