GUI /应用程序通信 [英] GUI /application communication

查看:68
本文介绍了GUI /应用程序通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理GUi /内部应用程序通信的最佳方法是什么。我有许多处理数据的基础线程,并希望将其输出发布到gui。

What is the best way to handle GUi/ internal application communication. I have many underlying threads processing data, and would like to post their output to the gui.

我应该拥有我所有可运行对象所拥有的某种处理程序对象,然后将它们发布到它,以便它可以将输出处理到gui?

Should I have some kind of handler object that is owned by all my runnables, and then have them post to it, so it can handle the output to the gui?

推荐答案

我通常使用观察者模式,用于进行此类交流。因此,基本上,您的线程类实现了使它们可观察的通用接口(addObserver()),而GUI控制器/视图实现了观察器接口(fireNewEvent())。如果线程产生了某种新内容,它将在观察者上调用一个方法。根据您的项目,可以将呈现的信息推送给观察者(例如fireNewEvent(Event e)),或者观察者可以自己访问信息( pull ) 。基本上,这就是您的想法,而且可以灵活地通知多个观察者(如果需要)。

I usually use an observer pattern for that kind of communication. So basically your thread classes implement a common interface (addObserver()) making them observables and your GUI controller/view implements the observer interface (fireNewEvent()) . If a thread has produced some kind of new content, it calls a method on the observer. Depending on your project the information to be presented can be pushed to the observer (e.g. fireNewEvent(Event e)) or the observer can access the information on its own (pull). Basically this is your idea plus the flexibility of notifying more than one observer (if needed).

这篇关于GUI /应用程序通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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