This needs no explanation.
[java]
public void actionPerformed(ActionEvent e) {
Thread thread = new Thread(new Runnable() {
public void run() {
doExpensiveOperation();
completed = true;
}
});
completed = false;
thread.start();

//Wait for expensive thread to complete.
while (!completed) {
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
[/java]

Advertisements