taborrg
asked on
Use mouseListener to trigger an event when the mouse is released.
Hi,
I'm trying to use mouseListener to trigger an event when the mouse is released.
Do I need a loop for this?
Thanks
I'm trying to use mouseListener to trigger an event when the mouse is released.
Do I need a loop for this?
Thanks
no need to loop, just override the "public void mouseReleased(MouseEvent e)" method of mouse listener
look here for an example how to write mouse listener:
http://www.iam.ubc.ca/guides/javatut99/uiswing/events/mouselistener.html
http://www.iam.ubc.ca/guides/javatut99/uiswing/events/mouselistener.html
ASKER
for_yan - How do I make use of that in a method?
Thanks
Thanks
You add MouseListener to some component and when
mosue is realesed on that component -say button or panel this mehod will be automatically called
then you put any activity which you want inside that methoid and it wil be executed:
public void mouseReleased(MouseEvent e) {
saySomething("Mouse released; # of clicks: "
+ e.getClickCount(), e);
}
mosue is realesed on that component -say button or panel this mehod will be automatically called
then you put any activity which you want inside that methoid and it wil be executed:
public void mouseReleased(MouseEvent e) {
saySomething("Mouse released; # of clicks: "
+ e.getClickCount(), e);
}
ASKER
for_yan
So each method in a class needs to have its own mouseListener?
If I have one in a class, can any method in that class make use of it?
Thanks
So each method in a class needs to have its own mouseListener?
If I have one in a class, can any method in that class make use of it?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No, your class implements MouseListener - it means you need only one method mouseRelaesed in a c lass, like in my example
ASKER
Great! Thanks for the help.
Then you cann addMouseListener(this)
to any number of components
and then when you get into method
you may check which of the com;omenets
caused the even - you just say
if(me.getSource().equals(p anle) {
//do somethingh
//return
}
if(me.getSource().equals(b utton){
//do something else
}
to any number of components
and then when you get into method
you may check which of the com;omenets
caused the even - you just say
if(me.getSource().equals(p
//do somethingh
//return
}
if(me.getSource().equals(b
//do something else
}
Thee is amethod
public void mouseRelaesed(MouseEvent me) {
}
this method will be called when mouse is relead