鼠标侦听器和动作侦听器之间的区别? [英] Difference between Mouse Listener and Action Listener?

查看:133
本文介绍了鼠标侦听器和动作侦听器之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么区别?什么时候使用鼠标侦听器?还是动作监听器? 谢谢,麻烦您了!

Whats the difference? When would you use a mouse listener? or a action listener? Please and Thank You!

推荐答案

ActionListener文档的

ActionListener Doc's

用于接收动作事件的侦听器界面.该类 有兴趣处理一个动作事件来实现这一点 接口,并且使用该类创建的对象已注册 组件,使用组件的addActionListener 方法.当动作事件发生时,该对象的 actionPerformed方法被调用.

The listener interface for receiving action events. The class that is interested in processing an action event implements this interface, and the object created with that class is registered with a component, using the component's addActionListener method. When the action event occurs, that object's actionPerformed method is invoked.

MouseListener文档的

MouseListener Doc's

用于接收有趣"鼠标事件的侦听器界面 (按,释放,单击,进入和退出)在组件上. (追踪 鼠标移动和鼠标拖动,请使用 MouseMotionListener.)

The listener interface for receiving "interesting" mouse events (press, release, click, enter, and exit) on a component. (To track mouse moves and mouse drags, use the MouseMotionListener.)

从文档中您可以看到此接口的用法完全不同.虽然只能将MouseListener与gui元素结合使用,但在没有gui时也可以使用ActionListener,例如与计时器结合使用.

From the docs you can see that the usage of this interfaces is completly different. While you can use the MouseListener only in combination with gui elements, the ActionListener is also used when there is no gui, for example in combination with a timer.

这篇关于鼠标侦听器和动作侦听器之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆