Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MouseAdapter class and mouseMoved

Tags:

java

events

If I register with addMouseListener a Component and then I pass it a new MouseAdapter the motions event aren't generated because I must use addMouseMotionListener...

and conversely if I use addMouseMotionListener with MouseAdapter I can't use click events ecc.

so really I don't understand why MouseAdapter implements also MouseMotionListener and MouseWheelListener...

it creates only confusion!

like image 888
xdevel2000 Avatar asked May 08 '26 03:05

xdevel2000


1 Answers

Because in this way you can exactly do what you want: listen for both motion and click events in the same listener class:

MouseAdapter adapter = new MouseAdapter ({
    // Override here all the methods you need
});

widget.addMouseListener(adapter);    
widget.addMouseMotionListener(adapter);

This way your adapter will be notified of both Motion and clicks events.

like image 199
Manuel Selva Avatar answered May 10 '26 18:05

Manuel Selva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!