如何首先调用 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
何时完成执行,您有一些基本选择。
第一个是重写 SwingWorker
的 done
方法,该方法在 doInBackground
退出后调用,但在美国东部时间
或者...
您可以将 PropertyChangeListener
附加到 SwingWorker
并监视 state
属性,检查该值是否为 SwingWorker。 StateValue.DONE
或者...
您可以调用 SwingWorker#get
,它将等待 doInBackground
方法存在,并返回 doInBackground
返回或将抛出的值导致 doInBackground
方法退出的 Exception
。
看看javax.swing.SwingWoker
和 Worker Threads and SwingWorker了解更多详情
关于java - 如何首先调用 swingworker 的执行方法,最后调用剩余代码这是我的代码 :-,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21153826/