可能有人解释EventQueue的对象用作什么目的? [英] Could someone explain what purpose EventQueue object serves?

查看:651
本文介绍了可能有人解释EventQueue的对象用作什么目的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释一下什么样的目的的EventQueue 对象服务于Java Swing的?

Could someone explain what purpose EventQueue object serves in Java Swing?

我主要是困惑的排队事件是如何被应用。也许提供共同使用一个事件队列将是有益的。

I'm mostly confused about how queuing events is applied. Maybe providing common use of an event queue would be helpful.

推荐答案

由于Swing是单线程,它使用 的EventQueue 持有的Runnable 的实例,使他们可以派出的连续的和在为了发布的,是否由系统或程序产生的。在必要条件的使用是通过 EventQueue.invokeLater发布一个事件(),这保证了Swing GUI的对象构造和操作的的在事件调度线程。你可以用自己的实现替换AWT 的EventQueue ,如下所示 ,以查看事件,因为它们被放置在队列中。

Because Swing is single threaded, it uses the EventQueue to hold instances of Runnable so that they can be dispatched sequentially and in the order posted, whether generated by the system or your program. The sine qua non usage is posting an event via EventQueue.invokeLater(), which ensures that Swing GUI objects are constructed and manipulated only on the event dispatch thread. You can replace the AWT EventQueue with your own implementation, as shown here, to see the events as they are placed in the queue.

这篇关于可能有人解释EventQueue的对象用作什么目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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