整个程序的可重用SwingWorker子类

时间:2014-04-22 06:36:30

标签: java swing swingworker

我需要制作一个通用SwingWorker进程才能在我的所有程序中使用它。 我的班级是这样的:

public class LoadingSwingWorker extends SwingWorker<Integer, Integer> {

    private WaitingDiag diag;

    private Statistics st = new Statistics();

    public LoadingSwingWorker(GraphEditor editor, Statistics st) {  //st variable
        this.st = st;
        Window mainWindow = SwingUtilities.windowForComponent(editor
                .getGraphComponent().getParent());
        diag = new WaitingDiag(mainWindow, "Loading data...");
    }

    @Override
    protected Integer doInBackground() throws Exception {
        st.loadInitialData();   //st method
        return 42;
    }

    @Override
    protected void done() {
        diag.dispose();
    }

    public void openDiag() {
        diag.setVisible(true);
    }
}

对于我的所有程序,我可能需要创建SwingWorker我需要的long_time任务(在这种情况下为st变量),是不可能的实现通用的

0 个答案:

没有答案