home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / enxle1f6 / src / games / battle / client / europaclient / errorwindow.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  1.7 KB  |  81 lines

  1. /*
  2.  * @(#)ErrorWindow.java
  3.  */
  4.  
  5. package games.Battle.client.EuropaClient;
  6.  
  7. import java.awt.*;
  8.  
  9. /**
  10.  * Implements a small modal dialog box which displays a single
  11.  * line of text along with an "ok" box. When executed, the
  12.  * dialog box suspends the calling EuropaClient instance, and
  13.  * does not return control until the "ok" button is pressed.
  14.  *
  15.  * @author Alex Nicolaou
  16.  * @author Jay Steele
  17.  */
  18. public class ErrorWindow extends Frame {
  19.  
  20.     /**
  21.      * The main client applet.
  22.      */
  23.     EuropaClient client;
  24.  
  25.     /**
  26.      * The ok button.
  27.      */
  28.     Button ok;
  29.  
  30.     /**
  31.      * The string inside the okay button.
  32.      */
  33.     String OK = "    Ok    ";
  34.  
  35.     /**
  36.      * Constructs a Error window as a child of the given client
  37.      * and displaying the given message.
  38.      * @param client the client to suspend while the dialog lives
  39.      * @param msg the error message to display
  40.      */
  41.     public ErrorWindow(EuropaClient client, String msg) {
  42.         //super(null, "Error", true);
  43.         super("Error");
  44.         this.client = client;
  45.  
  46.         Panel message = new Panel();
  47.         message.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 20));
  48.         message.add(new Label(msg));
  49.         add("North", message);
  50.  
  51.         Panel buttons = new Panel();
  52.         buttons.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 20));
  53.         buttons.add(ok = new Button(OK));
  54.         add("South", buttons);
  55.  
  56.         pack();
  57.  
  58.         ok.requestFocus();
  59.     }
  60.  
  61.     /**
  62.      * Handle the "ok" button.
  63.      */
  64.     public boolean handleEvent(Event e) {
  65.         if (e.id == Event.WINDOW_DESTROY || e.arg == OK) {
  66.             client.resume();
  67.             dispose();
  68.         }
  69.  
  70.         return super.handleEvent(e);
  71.     }
  72.  
  73.     /**
  74.      * Overload the layout() method to additionally call pack().
  75.      */
  76.     public synchronized void layout() {
  77.         pack();
  78.         super.layout();
  79.     }
  80. }
  81.