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(); }