MVP,JFrame,JDialog:GUI正在冻结 [英] MVP, JFrame, JDialog : GUI is freezing

查看:109
本文介绍了MVP,JFrame,JDialog:GUI正在冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有主框架(使用JFrame字段)asi 视图,然后是演示者(在视图的构造函数中创建),它将监听器添加到按钮和内容中。我这样做:

I have main frame (with JFrame field) asi view, then presenter (created in view's constructor) that adds listeners to buttons and stuff. I do that like this:

public static void main(final String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    MyWindow window = new MyWindow();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

MyWindow只在一个构造函数中调用一个方法 - 初始化 - 只创建GUI字段。最后(字面意思是它的代码的最后一行)它创建了演示者。

MyWindow invokes in it's constructor only one method - intialize - that only creates GUI fields. Finally (literally last line of it's code) it creates presenter.

Presenter应该在主视图中的某些事件上显示新的JDialog。它有一种方法,使我的GUI冻结。它看起来像这样:

Presenter should show new JDialog on certain events in main view. It has one method, that makes my GUI freeze. It looks like this:

protected double[] getParams(final Class<?> indicatorClass) {
        ParametrizableDialog dialog = dialogs.get(indicatorClass); // works well
        List<Double> params = new ArrayList<Double>();
        dialog.setParams(params);
        dialog.setModal(true);
        dialog.setLocationRelativeTo(view.getFrame());
        dialog.setVisible(true);
        System.out.println(params); // it actually works, params are obtained from JDialog as user input
        return Doubles.toArray(params); // guava
    }

ParametrizableDialog 是正常的 JDialog ,它实现了一个设置 List< Double >参数的方法接口,如下所示:

ParametrizableDialog is normal JDialog that implements one method interface that sets List<Double> parameters like this:

public class ParametrizableDialog extends JDialog implements Parametrizable {

    protected List<Double> params;

    @Override
    public void setParams(final List<Double> params) {
        this.params = params;
    }

}

现在,有人知道什么是错误我做了什么,为什么我的GUI冻结了?
谢谢!

Now, does anybody know what mistake did I make and why does my GUI freeze? Thanks!

推荐答案

如果GUI冻结,通常是因为你阻止了EDT。有关详细信息,请阅读并发上的Swing教程中的部分。

If a GUI freezes, its generally because your are blocking the EDT. Read the section from the Swing tutorial on Concurrency for more information.

由于您的代码不完整,我们无法判断您在做什么。例如,您甚至不向GUI添加任何组件。所以谁知道你在遗漏的代码中做了什么。

We can't tell what you are doing because your code isn't complete. For example you don't even add any components to the GUI. So who knows what you are doing in the code you left out.

如需更多帮助,请发布 SSCCE 证明了这个问题。

For more help post your SSCCE that demonstrates the problem.

这篇关于MVP,JFrame,JDialog:GUI正在冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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