"GUI while循环" [英] "GUI while loop"

查看:134
本文介绍了"GUI while循环"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个看起来像这样的代码:

Okay, I have a code that looks like this:

public class Test
{   

private JPanel dummy;

public checker()
{
    dummy = new JPanel();
    dummy.setVisible(false);

    dummy.addComponentListener(new ComponentAdapter()
    {
        @Override
        public void componentShown(ComponentEvent arg0)
        {
            dummy.setVisible(false);
            runCheck();
        }           
    });

    runCheck();
}


private void runCheck()
{
    if (a)
    {
        //do something
        dummy.setVisible(true);
    }
}

}

这将创建一个虚拟JPanel并添加一个组件适配器,该适配器将在每次将虚拟设置为可见时触发.它的工作方式类似于while循环,只是它确保GUI在进入另一个循环之前已更新.

This will create a dummy JPanel and add a component adapter that will fire each time dummy is set to be visible. It works like a while loop, only it makes sure that GUI is updated before it goes into another cycle.

但是一旦循环中断,我需要方法checker()返回一个值.

But I need method checker() to return a value once the cycle is broken.

注意: 这是代码的简化版本,我无法检查条件a,这不是解决方案.

NOTE: This is symplified version of code, I cannot check for condition a, that is not a solution.

推荐答案

我知道了.我可以使用 secondaryLoop .我无法解释它实际上是如何工作的,但是它使我可以冻结程序(但是EDT),并且在冻结代码的同时,将事件立即添加到EDT队列中(如果EDT不忙于做任何事情)其他,就我而言,不是).

I figured it out. I can use secondaryLoop. I am unable to explain how it actually works, but it enables me to freeze the program (but the EDT) and, while the code is frozen, add events to the EDT queue which are done immediatley (if EDT isn't busy doing anything else, which, in my case, isn't).

有关主题的更多信息:链接

More on topic: link

这篇关于"GUI while循环"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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