免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2278 | 回复: 1
打印 上一主题 下一主题

请教一个关于Listener的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-09-22 14:24 |只看该作者 |倒序浏览
ActionListener 好象能够实现很多 Listener的动作啊~比如MouseListener 和KeyListener 等等。
我现在就是糊涂了,如果ActionListener能把这些都实现,还要MouseListener 这些 Listener 做什么呢?

论坛徽章:
0
2 [报告]
发表于 2004-09-23 13:07 |只看该作者

请教一个关于Listener的问题

public interface ActionListener
extends EventListener
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.

public interface KeyListener
extends EventListener
The listener interface for receiving keyboard events (keystrokes). The class that is interested in processing a keyboard event either implements this interface (and all the methods it contains) or extends the abstract KeyAdapter class (overriding only the methods of interest).
The listener object created from that class is then registered with a component using the component's addKeyListener method. A keyboard event is generated when a key is pressed, released, or typed (pressedn and released). The relevant method in the listener object is then invoked, and the KeyEvent is passed to it.

public interface MouseListener
extends EventListener
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.)
The class that is interested in processing a mouse event either implements this interface (and all the methods it contains) or extends the abstract MouseAdapter class (overriding only the methods of interest).
The listener object created from that class is then registered with a component using the component's addMouseListener method. A mouse event is generated when the mouse is pressed, released clicked (pressed and released). A mouse event is also generated when the mouse cursor enters or leaves a component. When a mouse event occurs, the relevant method in the listener object is invoked, and the MouseEvent is passed to it.


我的理解是这样的:
Action listeners 应该理解为最简易而最普遍使用的事件处理机制。
既然它为最简易的,不妨理解它为一种通用的处理方式
那么通用中必然含有特殊,或者更为关注细节的情况
针对这些细微的情况,则应该产生一些专门的处理机制了
也就是说,他们不互相包含,但可以互相渗透和交叉(参数和处理机制可以不同)
他们的应用差别,楼主可以在今后的学习和探索中找到答案
希望有相关经验的朋友路过拍砖。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP