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.
IndexProcessing DevelopmentLibraries,  Tool Development › Quick Question about Events
Page Index Toggle Pages: 1
Quick Question about Events (Read 662 times)
Quick Question about Events
Oct 11th, 2007, 9:11pm
 
Hi,

I have a quick question about events (mouse, key, etc.) when creating a library. These event callbacks will only be fired when your class extends from PApplet correct?

If I have a class that just asks for a PApplet reference in the constructor... the events won't be fired for that class will they?

Thank you,
Mitchell Hashimoto
Re: Quick Question about Events
Reply #1 - Oct 11th, 2007, 11:22pm
 
Hi,

Today I managed to run processing in eclipse and I found out how to get a mouse event in a class without extending it from PApplet. I am not sure if this is really the best way to do it, but it seems to work. It is important to include "java.awt.event.MouseEvent" in the header:

import java.awt.event.MouseEvent;
import processing.core.PApplet;

public class myClass {
PApplet parent;
myClass(PApplet p) {
parent = p;
parent.registerMouseEvent(this);
}
public void mouseEvent(MouseEvent event) {
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: Quick Question about Events
Reply #2 - Oct 11th, 2007, 11:24pm
 
That makes sense.

Thanks! Smiley
Page Index Toggle Pages: 1