我有一个做事情的JFrame。我在那个JButton中隐藏了一个JFrame。在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
    }
}发布于 2014-04-12 10:19:21
doInBackground()的实现中更新GUI。process()或done()的实现中更新GUI,如这里和这里所示。checkNDownloadFile()方法,以便为合理的进度显示提供所需的粒度。https://stackoverflow.com/questions/23028825
复制相似问题