* possible de fermer la fenêtre via le gestionnaire de fenêtres.
*
* @author Arnaud Giersch <arnaud.giersch@univ-fcomte.fr>
- * @version 20141014
+ * @version 20141017
*/
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);
}
}
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!");
}
<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).