diff --git a/FormArtilleryConfig.java b/FormArtilleryConfig.java index da2a470..e2b2b3d 100644 --- a/FormArtilleryConfig.java +++ b/FormArtilleryConfig.java @@ -10,7 +10,6 @@ public class FormArtilleryConfig extends JFrame { private final EventListener eventHandler = new EventListener<>(); private DrawingArtillery artillery; - private JComponent draggedComponent; private JPanel contentPanel; private JPanel toolsPanel; private JPanel workspacePanel; @@ -70,13 +69,12 @@ public class FormArtilleryConfig extends JFrame { public void mousePressed(MouseEvent e) { super.mouseReleased(e); setCursor(new Cursor(Cursor.HAND_CURSOR)); - draggedComponent = (JComponent) e.getSource(); } @Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); - dispatchDrop(); + dispatchDrop((JComponent) e.getSource()); } }; @@ -107,13 +105,13 @@ public class FormArtilleryConfig extends JFrame { eventHandler.addListener(listener); } - public void dispatchDrop() { + public void dispatchDrop(JComponent droppedComponent) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - if (draggedComponent == null) { + if (droppedComponent == null) { return; } - if (draggedComponent instanceof JPanel panel) { + if (droppedComponent instanceof JPanel panel) { if (colorLabel.getMousePosition() != null) { artillery.setColor(panel.getBackground()); artillery.getRollers().setColor(panel.getBackground()); @@ -122,7 +120,7 @@ public class FormArtilleryConfig extends JFrame { advanced.setDopColor(panel.getBackground()); } } - if (draggedComponent instanceof JLabel label && pictureBox.getMousePosition() != null) { + if (droppedComponent instanceof JLabel label && pictureBox.getMousePosition() != null) { int speed = (Integer) speedSpinner.getValue(); int weight = (Integer) weightSpinner.getValue(); int rollersCount = (Integer) rollersSpinner.getValue(); @@ -141,7 +139,7 @@ public class FormArtilleryConfig extends JFrame { artillery.setRollers(new DrawingSquaredRollers(rollersCount, artillery.getArtillery().getBodyColor())); } } - draggedComponent = null; + repaint(); }