MouseAdapter类和mouseMoved

xde*_*000 3 java events

如果我使用addMouseListenerComponent 注册然后我传递了一个新MouseAdapter 的motions事件,因为我必须使用addMouseMotionListener...

反之,如果我用addMouseMotionListenerMouseAdapter,我不能使用点击事件ECC.

所以我真的不明白,为什么MouseAdapter还实现了MouseMotionListenerMouseWheelListener...

它只会产生混乱!

Man*_*lva 6

因为通过这种方式,您可以完全按照自己的意愿执行操作:在同一个侦听器类中侦听运动和单击事件:

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

widget.addMouseListener(adapter);    
widget.addMouseMotionListener(adapter);
Run Code Online (Sandbox Code Playgroud)

这样,您的适配器将收到Motion和点击事件的通知.