import java.awt.*; import java.awt.event.*; import utilities.*; public class DeadLockDialog implements ActionListener { private static DeadLockDialog it; private static Frame window; private static Label msgLabel; private static Thread client; static { it = new DeadLockDialog(); // singleton ! } //------------------------------------------------------------------- // DeadLockDialog Constructor //------------------------------------------------------------------- private DeadLockDialog() { window = new Frame(""); msgLabel = new Label("dummy", Label.CENTER); Button dismiss = new Button(" OK "); dismiss.addActionListener(this); Panel buttonPanel = new Panel(); buttonPanel.add(dismiss); window.add("Center", msgLabel); window.add("South" , buttonPanel); } //------------------------------------------------------------------- // Convenient static method to call up a dialog at any time, any place. //------------------------------------------------------------------- public static void popup(String message) { msgLabel.setText(message); window.pack(); window.setVisible(true); client = Thread.currentThread(); // like a sleeping beauty, go to sleep forever // only actionPerformed() can awaken us MiscKit.delay(Long.MAX_VALUE); } //------------------------------------------------------------------- // ActionListener interface method //------------------------------------------------------------------- public void actionPerformed(ActionEvent actionEvent) { window.setVisible(false); // client thread went into a deep sleep, interrupt sleep. client.interrupt(); } //------------------------------------------------------------------- // main() entry point //------------------------------------------------------------------- public static void main (String[] args) { DeadLockDialog.popup("Hello, I'm a philosophical dialog!"); MiscKit.delay(1000); DeadLockDialog.popup("Hello, I'm another philosophical dialog!"); MiscKit.delay(1000); DeadLockDialog.popup("Hello, yes.. I too am a philosophical dialog!"); System.exit(0); } } // End of Class DeadLockDialog