首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将JButton传递给实用程序类。可以接受吗?

将JButton传递给实用程序类。可以接受吗?
EN

Stack Overflow用户
提问于 2014-04-12 09:55:30
回答 1查看 77关注 0票数 0

我有一个做事情的JFrame。我在那个JButton中隐藏了一个JFrame。在SwingWorker中,我有一个实用工具类,比如checkNDownloadFile,我将一个JButton传递给它。因此,当流程完成时,它可以使其可见/可用。

我的问题是,这是否可以接受。我不知道有什么其他方法能达到这个效果。(请记住,checkNDownloadFile类都是静态的。它只需要一次/运行一次。

数独码

代码语言:javascript
运行
复制
-----------------------------------------------------------------
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
    }
}

应答码

代码语言:javascript
运行
复制
-----------------------------------------------------------------
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
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-12 10:19:21

  1. 不要从doInBackground()的实现中更新GUI。
  2. process()done()的实现中更新GUI,如这里这里所示。
  3. 您可能必须重新考虑您的checkNDownloadFile()方法,以便为合理的进度显示提供所需的粒度。
  4. 另见http://docs.oracle.com/javase/tutorial/essential/io/notification.html
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23028825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档