// This Class is (c)opyright 1999 by Geoff Knagge. It may be freely used // for any non-commercial purpose on the following conditions: // 1. You indemnify the copyright holder of all possible liability // resulting from its use. // 2. You provide a link back to the source of this file, that is // http://browse.to/gogogeoff // // Use of this class shows your agreement to the above. import java.awt.*; import java.awt.event.*; public class MessageBox extends Dialog implements ActionListener, WindowListener { Button OK; //// Any object implementing an WindowListener must include these public void windowClosing (WindowEvent e) { setVisible(false); // switch off the dialog... } public void windowActivated (WindowEvent e) {} public void windowClosed (WindowEvent e) {} public void windowDeactivated (WindowEvent e) {} public void windowDeiconified (WindowEvent e) {} public void windowIconified (WindowEvent e) {} public void windowOpened (WindowEvent e) {} //// This method is required by ActionListener classes... /// this one is bound only to the OK button public void actionPerformed(ActionEvent e) { setVisible(false); } // Constructor public MessageBox(Frame f,String message, String title) { super(f,title,true); // pass parameters to the Dialog() // constructor setBackground(new Color(96,192,255)); setLayout(new GridLayout(3,1)); // 3 rows, 1 column Label thisGuess = new Label(message); OK = new Button(" OK "); add(thisGuess); add(new Label(" ")); add(OK); OK.addActionListener(this); addWindowListener(this); } public static void popUp(Frame f,String message, int width, String title) { MessageBox Q = new MessageBox(f,message,title); Q.setSize(width,200); Q.setVisible(true); Q.dispose(); // free up memory after calling... } }