如何首先调用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
退出后调用,但在EDT的上下文中调用
或。。。
您可以将PropertyChangeListener
附加到SwingWorker
并监视state
属性,检查该值是否SwingWorker.StateValue.DONE
或。。。
您可以调用SwingWorker#get
它将等到doInBackground
方法存在并返回doInBackground
返回的值,或者将引发导致doInBackground
方法退出的Exception
。
查看 javax.swing.SwingWoker
和 Worker 线程和 SwingWorker 以获取更多详细信息