ユーザーの操作を待ちたい場合(ユーザーがボタンを押すまで待つ場合)、このアプローチが正しいかどうかを確認したいだけです。
SomeDialog someDialog = new SomeDialog(frame);
someDialog.setVisible(true);
try {
synchronized (someDialog) {
someDialog.wait();
}
} catch (InterruptedException ex) {
Logger.getLogger(SomeDialog.class.getName()).log(Level.SEVERE, null, ex);
}
int a = 0; a++; // <---- this line should not be processed before user clicks a button
その後:
someDialogButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
synchronized (SomeDialog.this) {
SomeDialog.this.notify();
}
}
});