WinA と WinB の 2 つの jframe があります。また、プロセスを実行するクラス Callable もあります。
WinA には、Callable を使用してスレッドでプロセスを実行するボタンがあり、WinB にはプログレスバーが表示されます。
WinA
クラス コード - ボタンの ActionPerformed。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
WinA wa = new WinA();
WinB wb = new WinB();
ClaseCallable callbd = new ClaseCallable();
ExecutorService exesrv = Executors.newSingleThreadExecutor();
Future sresp;
sresp = exesrv.submit(callbd);
wb.getProgressbar().setIndeterminate(true);
wb.setVisible(true);
System.out.println(">>" + sresp.get());
exesrv.shutdown();
wb.setVisible(false);
} catch (InterruptedException | ExecutionException ex) {
Logger.getLogger(WinA.class.getName()).log(Level.SEVERE, null, ex);
}
}
ClaseCallable
クラスコード
public class ClaseCallable implements Callable<Integer> {
@Override
public Integer call() throws Exception {
for(int i=0; i<10; i++){
Thread.sleep(250);
}
return 33;
}
}
から実行しWinA
てボタンを押すと、ウィンドウが開きますWinB
が、ウィンドウは白く、最後に結果が表示されます。
EDT スレッドでイベントを実行してスイングし、別のスレッドで処理している場合、なぜこれが発生するのか理解できません。