import java.awt.*; import java.awt.event.*; /* A modal dialog box that allows the invoker to block waiting for a response. With this primitive implementation, the creating/invoking context must dispose of the dialog after use--an instance cannot be reused. */ public class BlockingDialog extends Dialog implements ActionListener { boolean stillWaiting = true; public BlockingDialog(Frame parent, String title, boolean modal) { super(parent, title, modal); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { finish(); } }); } public void actionPerformed(ActionEvent e) { finish(); } public void finish() { responded(); setVisible(false); } public synchronized void waitForResponse() { try { while (stillWaiting) wait(); } catch (Exception e) {} } public synchronized void responded() { stillWaiting = false; notifyAll(); } }