我应该在哪里调用Java MVC模式中的swingworker [英] Where should I invoke my swingworker in a Java MVC pattern

查看:41
本文介绍了我应该在哪里调用Java MVC模式中的swingworker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与该MVC示例中的程序基本相同的程序: http://www.leepoint.net/notes-java/GUI/structure/40mvc.html

I have a program that is basically set up just like the one in this MVC example: http://www.leepoint.net/notes-java/GUI/structure/40mvc.html

在我的程序中,有一个过程需要花费很多时间才能冻结我的GUI.我想让GUI在进程运行时不断更新.为此,我相信我需要使用SwingWorker.我不知道我应该在MVC模式中的哪个位置调用此SwingWorker.

In my program there is a process which takes quite a bit of time which freezes my GUI. I want to GUI to continuously update while the process is running. To do this I believe I need to use a SwingWorker. I don't know where in my MVC pattern I should be invoking this SwingWorker.

我的想法是我应该在控制器的MultiplyListener actionlistener中运行它.这是正确的吗?

My thinking is that I should be running it in the MultiplyListener actionlistener of the controller. Would this be correct?

推荐答案

在这种情况下,模型是一种数学运算,它可能随着时间的推移而演化,可能是通过迭代而演化的.显然,工作人员属于模型,如此处所示. setProgress()方法将通知任何PropertyChangeListener,并且process()可以通知任何其他正在监听的 view ,如

In this case, the model is a mathematical operation that evolves over time, perhaps by iteration. Clearly, the worker belongs in the model, as shown here. The setProgress() method will notify any PropertyChangeListener, and process() can notify any other listening view, as shown here.

附录:在第二个示例中,工作人员更新了不同的模型:图表的名为collection的数据集.相应地,图表会侦听数据集并根据更改进行更新.

Addendum: In the second example, the worker updates a different model: the chart's dataset named collection. The chart, in turn, listens to the dataset and updates itself in response to the change.

引用的示例中, controller 代表 model view 安装动作侦听器.在此相关的示例中,GUI动作侦听器位于各自的视图的本地.无论哪种情况, Action 都是合适的选择用于封装. 模型会在其内部状态响应用户启动的操作而发生变化时通知其观察者.

In the example cited, the controller installs action listeners on behalf of the model and view. In this related example, the GUI action listeners are local to their respective views. In either case, Action would be a suitable choice for encapsulation. The model notifies its observers when its internal state changes in response to user initiated actions.

这篇关于我应该在哪里调用Java MVC模式中的swingworker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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