有人可以解释EventQueue对象的用途吗? [英] Could someone explain what purpose EventQueue object serves?
问题描述
有人可以解释什么目的 EventQueue
对象在Java Swing中服务?
我最困惑的是队列事件被应用。可能提供事件队列的常见用法将是有帮助的。因为Swing是单线程,它使用 EventQueue
来保存 Runnable
的实例,以便它们可以顺序发送 em>订单发布,无论是由系统还是您的程序生成。 sine qua non 用法是通过 EventQueue.invokeLater()
发布一个事件,这确保了仅仅构建和操纵Swing GUI对象在事件发送线程上。您可以将AWT EventQueue
替换为您自己的实现,如此处,查看事件放在队列中。
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.
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屋!