简体   繁体   中英

How to make responsive MVP Swing GUI in Java?

I have an application that is built on passive MVP architecture using Swing in Java 7. My Presenter class does some time-consuming tasks and my View/GUI just calls the presenter's methods after an event. The presenter calls view's methods to update GUI.

Obviously, I don't want the long-running tasks to happen on EDT.

My first thought was to use a SwingWorker, but since it has only one doInBackground method, I think I would have to implement a SwingWorker for every single one method in Presenter. Or would I?

Is there a simple way to make View/GUI run on EDT and everything else (ie Presenter's logic without it's calls to update View) on another (worker) thread?

You could create your SwingWorker on the spot and wrap each presenter's code in that SwingWorker and call it, along the lines of a Command design pattern. The devil of course will be in the details, including the details of your code, information that we don't have right now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM