From 680274195d55ba6c6aeaa29b893cd899a68b77fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Mon, 7 Nov 2022 15:32:44 +0400 Subject: [PATCH] Some fixes --- FormArtilleryConfig.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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(); }