如何用自己的实现替换AWT EventQueue [英] How to replace the AWT EventQueue with own implementation

查看:363
本文介绍了如何用自己的实现替换AWT EventQueue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了调试Swing应用程序中的奇怪行为,我想用我自己的实现替换AWT EventQueue。

In order to debug strange behavior in a Swing-application I'd like to replace the AWT EventQueue with my own implementation.

这可能吗?如何?

万一你感兴趣:


  • 实现将是一个围绕正常Eventqueue的简单包装器,进行一些日志记录。

  • the implementation will be a simple wrapper around the normal Eventqueue, doing some logging.

我要调试的问题是一个TableCellEditor,它可以正常运行小型演示应用程序,但是当放入真正的应用程序时,由于某些事件,会立即调用stopCellEditing。我希望能够访问该事件,以便了解它的来源。

the problem I'd like to debug is a TableCellEditor, which works fine in a little demo app, but when put in the real application, stopCellEditing gets called immediately, due to some event. I'd like to get access to the event in order to find out, where it is comming from.

推荐答案

EventQueue有一个名为push()的方法,可以完全按照你想要的方式执行。这是一个小小的演示:

EventQueue has a method called push() that will do exactly what you want. Here is a little demo:

public class QueueTest {
    public static void main(String[] args) throws InterruptedException, InvocationTargetException {
        EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        eventQueue.push(new MyEventQueue());

        EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                System.out.println("Run");
            }
        });
    }

    private static class MyEventQueue extends EventQueue {
        public void postEvent(AWTEvent theEvent) {
            System.out.println("Event Posted");
            super.postEvent(theEvent);
        }
    }
}

这篇关于如何用自己的实现替换AWT EventQueue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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