【发布时间】:2014-04-12 09:55:30
【问题描述】:
我有一个做事的 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
}
}
【问题讨论】:
标签: java swing static jframe jbutton