Wednesday, 15 September 2010

java - Using mouseClicked and mouseDragged at the same time -



java - Using mouseClicked and mouseDragged at the same time -

i trying utilize mouseclicked , mousedragged in java @ same time. mouseclicked belongs mouselistener , mousedragged belongs mousemotionlistener. help appreciated, thanks.

for convience, take @ mouseadapter implements mouselistener, mousemotionlistener , mousewheellistener

mouseadapter ma = new mouseadapter() { public void mouseclicked(mosueevent evt) { // ever here } public void mousedragged(mosueevent evt) { // ever here } } yourcomponent.addmouselistener(ma); yourcomponent.addmousemotionlistener(ma);

see how write mouse listener more details

equally, create own class...

public class myawesomemousehandler implements mouselistener, mousemotionlistener { // implement required methods... }

then create instance add together register them...

myawesomemousehandler handler = new myawesomemousehandler(); yourcomponent.addmouselistener(handler); yourcomponent.addmousemotionlistener(handler);

you implement listeners separatly , register them separatly...

java

No comments:

Post a Comment