We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › MouseEvent Handling
Page Index Toggle Pages: 1
MouseEvent Handling (Read 1690 times)
MouseEvent Handling
Nov 18th, 2007, 5:34am
 
I'm trying to figure out how Processing handles mouse events so I can translate it over to Java.

I've created a working version of Connect 4 in Processing, and so far have translated portions of it into Java. It works perfectly in Processing, but when I extend MouseListener things go really wonky. It should alternate on MouseReleased between two different color pieces and let you drop them manually, but when I include Java's mouse listener it starts dropping two pieces (instead of one) per click on random parts of the board. So far I've successfully implemented KeyListener so I know it's possible with the MouseListener as well, I just don't know how to go about fixing it.
Re: MouseEvent Handling
Reply #1 - Nov 18th, 2007, 5:05pm
 
hi,

you could use PApplet to register your mouse/keyEvents like this:
(like explained here http://dev.processing.org/libraries/ )

class gamePiece {

 gamePiece(...) {
   parent.registerMouseEvent(this);
 }

 public void mouseEvent(MouseEvent event) {
 int x = event.getX();
 int y = event.getY();

 switch (event.getID()) {
   case MouseEvent.MOUSE_PRESSED:
     // do something for the mouse being pressed
     break;
   case MouseEvent.MOUSE_RELEASED:
     // do something for mouse released
     break;
   case MouseEvent.MOUSE_CLICKED:
     // do something for mouse clicked
     break;
   case MouseEvent.MOUSE_DRAGGED:
     // do something for mouse dragged
     break;
   case MouseEvent.MOUSE_MOVED:
     // umm...
     break;
 }
}

}
Re: MouseEvent Handling
Reply #2 - Nov 18th, 2007, 6:50pm
 
Thanks a lot! The link you put up is really helpful too, I'll be sure to take a look at that from now on when I'm translating my stuff into Java.
Page Index Toggle Pages: 1