我有一个可以做事情的JFrame。我在JFrame中隐藏了一个JButton视图。在SwingWorker中,我有一个实用程序类,例如checkNDownloadFile,我将JButton传递给它。因此,当流程完成时,它可以使其可见/可用。
我的问题是,这是否可以接受。我不知道有任何其他方法来做这个效果。 (请记住,checkNDownloadFile类是静态的。它只需要/运行一次。)
-----------------------------------------------------------------
myWorker Class
protected Void doInBackground() throws Exception {
//Loading time consuming data.
//Execute Dialog of the question variety.
//Loading more time consuming data.
//Create JFrame
AtomFrame frame = new AtomFrame();
frame.start();
checkNDownloadFile.setButton(frame.fileButton)
checkNDownloadFile.start();
return null;
}
-----------------------------------------------------------------
checkNDownloadFile Class
public static void start() {
//Do the other task at hand
if (complete && good) {
fileButton.setVisible(true);
} else {
//other stuff
}
}
-----------------------------------------------------------------
myWorker Class
protected Void doInBackground() throws Exception {
//Loading time consuming data.
//Execute Dialog of the question variety.
//Loading more time consuming data.
//Create JFrame
//Moved to Main Method to be created by EDT.
//AtomFrame frame = new AtomFrame();
//frame.start();
publish("Executing");
boolean returnedB = checkNDownloadFile.start();
if (returnedB) {
publish("Good");
} else {
//Maybe implement
//checkNDownloadFile.getError();
publish("Bad");
}
return null;
}
-----------------------------------------------------------------
checkNDownloadFile Class
public static void start() {
//Do the other task at hand
if (complete && good) {
return true
} else {
//Maybe implement
//setError("");
return false
}
}
答案 0 :(得分:2)
不要从doInBackground()
的实施中更新GUI。
您可能需要重新考虑checkNDownloadFile()
方法,以便为合理的进度显示提供所需的粒度。