gpt4 book ai didi

java - 如何添加线程 MVC 模式 theView 以避免 JFrame 卡住

转载 作者:行者123 更新时间:2023-12-01 23:08:01 25 4
gpt4 key购买 nike

我想使用线程运行 GUI 以避免卡住问题,如何添加线程来查看?或者您对避免 GUI 卡住问题有什么总体想法吗?

public class Vark {

public static void main(String[] args) {
// Object Creation For the View
VarkView theView = new VarkView();
// Object Creation For the Model
VarkModel theModel = new VarkModel();
// Object Creation For the Controller passing theModel and theView
VarkController theController = new VarkController(theView, theModel);
theView.setVisible(true);
}
}

最佳答案

简单的答案是大部分工作在 GUI 线程上完成,只有时间密集型作业放在单独的线程上(阅读有关创建新线程、Runnable 接口(interface)、ThreadPoolExecutor 和 Callable 接口(interface)的信息)。

一般来说,有很多工作模式。对于初学者来说,它可能是生产者/消费者模式。

与往常一样,线程不要忘记保护共享数据(同步、锁),甚至更好 - 避免在线程之间共享数据:)

关于java - 如何添加线程 MVC 模式 theView 以避免 JFrame 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22480870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com