LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 741|回复: 3

基于事件编程的疑惑。

[复制链接]
发表于 2005-3-1 18:56:50 | 显示全部楼层 |阅读模式
当某一事件激活时,
系统会到注册的监听器调用此事件的方法。

我想知道的是:
每个事件被激活时,
是否是启动另一个线程,
来处理方法里定义的代码?

或者说:
当事件被激活时,
代码还没运行结束,
这个事件再此被激活。
那么,
第一次激活时的代码是运行完了,
再执行第二次被激活的代码?
还是一起运行?
还是怎么的?

PS:我的程序中使用的基于事件的监听器不是GUI中的Listener。
发表于 2005-3-1 20:47:35 | 显示全部楼层
http://java.sun.com/docs/books/t ... html#handlingEvents
页面的最下面有一个note如下:
Note: Event-handling code executes in an single thread, the event-dispatching thread. This ensures that each event handler finishes execution before the next one executes. For instance, the actionPerformed method in the preceding example executes in the event-dispatching thread. Painting code also executes in the event-dispatching thread. Therefore, event-handling code should execute quickly so that the program抯 GUI stays responsive. If an event takes too long to execute, the GUI will freeze--that is, it won抰 repaint or respond to mouse clicks. Writing Event Listeners (in the Creating a GUI with JFC/Swing trail) has for more information.
大概的意思就是事件处理方法都是在一个单线程(event-dispatching thread)里处理的,也就是说如果有多个evenet listener,它们是顺序执行的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-3-1 21:17:08 | 显示全部楼层
非常感谢!
回复 支持 反对

使用道具 举报

发表于 2005-3-1 21:30:50 | 显示全部楼层
不客气,我也是跟着你这个问题,查了些资料,长了些知识,大家共同成长吧 :-)
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表