如何首先调用 swingworker 的执行方法,最后调用剩余代码这是我的代码:-



如何首先调用swingworker 的执行方法,最后调用剩余代码。我能为它做些什么?

            imgHeight = getImageHeight(temp);
            imgWidth = getImageWidth(temp);    

            int Matrix = new int [imgHeight][imgWidth][3];
            MapGeneration.execute(); 

            //Matrix here
            Image lImage = Util.RGBMatrixToImage(imgHeight, imgWidth, Matrix);


protected int[][][] doInBackground() throws Exception
{      
    Matrix = createMap(imgHeight, imgWidth, imageMatrix, k);             
    return Matrix;        
}
   Can I use this returned Matrix on other page or to run execute() method at first

如果你想知道SwingWorker何时完成执行,你有几个基本的选择。

第一种是覆盖SwingWorkerdone方法,该方法在doInBackground退出后调用,但在EDT的上下文中调用

或。。。

您可以将PropertyChangeListener附加到SwingWorker并监视state属性,检查该值是否SwingWorker.StateValue.DONE

或。。。

您可以调用SwingWorker#get它将等到doInBackground方法存在并返回doInBackground返回的值,或者将引发导致doInBackground方法退出的Exception

查看 javax.swing.SwingWoker 和 Worker 线程和 SwingWorker 以获取更多详细信息

最新更新