我有一个场景,我需要我的 swing UI 在两个不同的线程上运行。我有一台笔记本电脑,我将在其中运行我的应用程序。在连接到我的笔记本电脑的另一个屏幕上单击应该开始演示文稿有一个按钮。
现在我做了一个扩展 SwingWorker 的课堂演示,并从文件夹中读取图像并将其显示在屏幕上。
class Presenatation extends SwingWorker<Integer, Integer> {
@Override
protected Integer doInBackground() throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
start(outputFolder, screenVO);/*Creates a JFrame to be displayed
on new screen and sets a JPanel to it. Reads the file images sets it into
JLabels every 2 seconds and updates it to Japnel*/
}
});
return null;
}
在我的 start 方法中,我有读取图像并在 UI 上显示它们的代码
我觉得这种方法是错误的,因为我的 SwingWorker 不应该在 doInBackground() 中调用 invokeLater
据我所知,它应该是这样的:
@Override
protected Void doInBackground() throws Exception
{
return null;
}
@Override
protected void process(List<Integer> chunks
{
}
我无法决定哪个部分应该放在哪里?
我有以下事情要做:
- 开始一个新的框架以在新屏幕上显示
- 每 2 秒将图像加载到框架中,从文件夹中读取图像
- 将 Presentation 类扩展到 SwingWorker,这种方法正确吗?因为在外部我有一个 Executor 对象,我在其 exec() 中传递了 Presentation 对象
请帮我 !