1
방금 스윙 백그라운드 작업을 실행하는 방법을 배웠고 실험을 시작했지만 구현에 약간의 문제가 있습니다. 내 코드는 이미지를 검색하고 이미지 검색이 성공적인지 여부를 나타내는 결과 (정수)를 반환합니다. 결과는 0 또는 실패한 결과 = -1입니다. 여기에 내 문제가있다, 나는 너무 빨리 결과를 검색하고있다. done() 메서드에서 결과를 읽은 후 실행중인 코드에서 createImage 메서드의 문을 볼 수 있습니다. createImage가 완료 될 때까지 완료된 메서드가 실행되지 않을 것이라고 생각합니다. 다음은 내 코드입니다.자바 스윙 작업자 구현 문제
new SwingWorker<int[], Void>() {
int result = -1;
@Override
protected int[] doInBackground() throws Exception {
// TODO Auto-generated method stub
return createImage(); //returns an integer array of size one indicating the result
}
protected void done() {
try {
result = get()[0]; //this result is being read before createImage is done
//executing. Why?
thisApplet.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
tree.setEnabled(true);
if (result == -1){
tree.setSelectionPath(null);
return;
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}.execute();
예. 바보 같은 프로그래밍 오류. 내가 고칠 때 모든 것이 효과가 있었다. – Elliott