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

查看:29
本文介绍了如何用自己的实现替换 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.

这可能吗?怎么样?

以防万一您有兴趣:

  • 这个实现将是一个简单的事件队列的包装器,做一些日志记录.

  • 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天全站免登陆