Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make the JPanel listen for mouse events!.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 17 Oct 2014 12:09:50 +0000 (14:09 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 17 Oct 2014 12:12:00 +0000 (14:12 +0200)
DrawingWindow.java
Test.java
overview.html

index b292dc7..fe13798 100644 (file)
@@ -34,7 +34,7 @@ import javax.swing.JPanel;
  * possible de fermer la fenêtre via le gestionnaire de fenêtres.
  *
  * @author Arnaud Giersch &lt;arnaud.giersch@univ-fcomte.fr&gt;
- * @version 20141014
+ * @version 20141017
  */
 public class DrawingWindow {
 
@@ -743,7 +743,7 @@ public class DrawingWindow {
         frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
         frame.addWindowListener(new DWWindowHandler());
         frame.addKeyListener(new DWKeyHandler());
-        frame.addMouseListener(new DWMouseHandler());
+        panel.addMouseListener(new DWMouseHandler());
         frame.setLocationByPlatform(true);
         frame.setVisible(true);
     }
index 65a891f..d3e4e62 100644 (file)
--- a/Test.java
+++ b/Test.java
@@ -45,9 +45,16 @@ class Test{
         }
         w2.closeGraph();
 
-        while (w1.waitMousePress(5 * 1000))
-            System.out.println("[ " + w1.getMouseX() + " ; " + w1.getMouseY() +
-                               " ] -- button " + w1.getMouseButton());
+        System.out.println("Click anywhere on w1...");
+
+        while (w1.waitMousePress(5 * 1000)) {
+            int x = w1.getMouseX();
+            int y = w1.getMouseY();
+            System.out.println("[ " + x + " ; " + y + " ] - " +
+                               w1.getMouseButton());
+            w1.drawLine(x - 5, y, x + 5, y);
+            w1.drawLine(x, y - 5, x, y + 5);
+        }
 
         System.out.println("Done!");
     }
index bd8e2f3..3e9d112 100644 (file)
     <h2>Modifications</h2>
 
     <p><pre>
+-- ven. 17 oct. 2014 14:09:50 +0200
+
+        * Correction d'un décalage avec getMouse{X,Y}.
+
 -- lun. 14 oct. 2014 22:10:45 +0200
 
         * Ajout des méthodes setColor(int) et setBgColor(int).