@@ -2772,10 +2772,14 @@ protected void handleMouseEvent(MouseEvent event) {
27722772 // also prevents mouseExited() on the mac from hosing the mouse
27732773 // position, because x/y are bizarre values on the exit event.
27742774 // see also the id check below.. both of these go together.
2775- // Not necessary to set mouseX/Y on PRESS or RELEASE events because the
2776- // actual position will have been set by a MOVE or DRAG event.
2777- if (event.getAction() == MouseEvent.DRAG ||
2778- event.getAction() == MouseEvent.MOVE) {
2775+ // Not necessary to set mouseX/Y on RELEASE events because the
2776+ // actual position will have been set by a PRESS or DRAG event.
2777+ // However, PRESS events might come without a preceeding move,
2778+ // if the sketch window gains focus on that PRESS.
2779+ final int action = event.getAction();
2780+ if (action == MouseEvent.DRAG ||
2781+ action == MouseEvent.MOVE ||
2782+ action == MouseEvent.PRESS) {
27792783 pmouseX = emouseX;
27802784 pmouseY = emouseY;
27812785 mouseX = event.getX();
@@ -2809,7 +2813,7 @@ protected void handleMouseEvent(MouseEvent event) {
28092813 // Do this up here in case a registered method relies on the
28102814 // boolean for mousePressed.
28112815
2812- switch (event.getAction() ) {
2816+ switch (action ) {
28132817 case MouseEvent.PRESS:
28142818 mousePressed = true;
28152819 break;
@@ -2820,7 +2824,7 @@ protected void handleMouseEvent(MouseEvent event) {
28202824
28212825 handleMethods("mouseEvent", new Object[] { event });
28222826
2823- switch (event.getAction() ) {
2827+ switch (action ) {
28242828 case MouseEvent.PRESS:
28252829// mousePressed = true;
28262830 mousePressed(event);
@@ -2849,8 +2853,8 @@ protected void handleMouseEvent(MouseEvent event) {
28492853 break;
28502854 }
28512855
2852- if ((event.getAction() == MouseEvent.DRAG) ||
2853- (event.getAction() == MouseEvent.MOVE)) {
2856+ if ((action == MouseEvent.DRAG) ||
2857+ (action == MouseEvent.MOVE)) {
28542858 emouseX = mouseX;
28552859 emouseY = mouseY;
28562860 }
0 commit comments