diff options
Diffstat (limited to 'NET/worlds/console/BlockingDialog.java')
| -rw-r--r-- | NET/worlds/console/BlockingDialog.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/NET/worlds/console/BlockingDialog.java b/NET/worlds/console/BlockingDialog.java new file mode 100644 index 0000000..b32b5b8 --- /dev/null +++ b/NET/worlds/console/BlockingDialog.java @@ -0,0 +1,47 @@ +package NET.worlds.console; + +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +public class BlockingDialog extends Dialog implements ActionListener { + private static final long serialVersionUID = 8379457384966170912L; + boolean stillWaiting = true; + + public BlockingDialog(Frame parent, String title, boolean modal) { + super(parent, title, modal); + this.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + BlockingDialog.this.finish(); + } + }); + } + + @Override + public void actionPerformed(ActionEvent e) { + this.finish(); + } + + public void finish() { + this.responded(); + this.setVisible(false); + } + + public synchronized void waitForResponse() { + try { + while (this.stillWaiting) { + this.wait(); + } + } catch (Exception var2) { + } + } + + public synchronized void responded() { + this.stillWaiting = false; + this.notifyAll(); + } +} |