home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / enxle1f6 / src / games / battle / client / clientapplet / clientabortdialog.java next >
Encoding:
Java Source  |  1996-08-14  |  3.0 KB  |  140 lines

  1. /*
  2.  * @(#)ClientAbortDialog.java
  3.  */
  4.  
  5. package games.Battle.client.ClientApplet;
  6.  
  7. import java.awt.*;
  8. import java.applet.*;
  9. import java.lang.*;
  10.  
  11. /**
  12.  * A specialized dialog class used for shutting down the game
  13.  * client in the event of a communication problem with the
  14.  * game server.
  15.  *
  16.  * @author Alex Nicolaou
  17.  * @author Jay Steele
  18.  */
  19. public class ClientAbortDialog extends Frame {
  20.  
  21.     /**
  22.      * The parent applet
  23.      */
  24.     Applet applet;
  25.  
  26.     /**
  27.      * The thread which gets suspended and resumed to make
  28.      * this dialog modal.
  29.      */
  30.     Thread thread;
  31.  
  32.     /**
  33.      * The dialog box message.
  34.      */
  35.     TextArea message;
  36.  
  37.     /**
  38.      * The Retry and Abort buttons panel.
  39.      */
  40.     Panel buttons;
  41.  
  42.     /**
  43.      * The abort button.
  44.      */
  45.     Button abort;
  46.  
  47.     /**
  48.      *  The retry button.
  49.      */
  50.     Button retry;
  51.  
  52.     /*
  53.      * Flag indicating which button has focus.
  54.      */
  55.     int focus = 0;
  56.  
  57.     /*
  58.      * An array of all of the buttons.
  59.      */
  60.     Component[] fields;
  61.  
  62.     /**
  63.      * Builds the dialog box, telling it which applet to kill
  64.      * if the user requests it, and which thread to suspend
  65.      * to make the dialog box appear modal. The suspended
  66.      * thread is resumed when the dialog box is closed.
  67.      * @param applet the applet to resume or kill
  68.      * @param thread the thread to block on to give modal behaviour
  69.      */
  70.     public ClientAbortDialog(Applet applet, Thread t) {
  71.         // super(null, "Time-out warning", true);
  72.         super("Time-out warning");
  73.  
  74.         this.applet = applet;
  75.         this.thread = t;
  76.  
  77.         setLayout(new BorderLayout(80, 10));
  78.  
  79.         if (message != null)
  80.             message.removeNotify();
  81.  
  82.         message = new TextArea();
  83.         message.setEditable(false);
  84.         String msg;
  85.         msg = "Warning!\n";
  86.         msg = msg+"The client application does not seem to be communicating\n";
  87.         msg = msg+"with the server. You can attempt to regain contact by\n";
  88.         msg = msg+"pressing \"retry\" or you can kill this particular game\n";
  89.         msg = msg+"client and try to connect again by pressing \"abort\".\n";
  90.         message.appendText(msg);
  91.  
  92.         add("Center", message);
  93.  
  94.         if (buttons != null)
  95.             buttons.removeNotify();
  96.  
  97.         buttons = new Panel();
  98.         buttons.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10));
  99.         buttons.add(retry = new Button("Retry"));
  100.         buttons.add(abort = new Button("Abort"));
  101.         add("South", buttons);
  102.         pack();
  103.  
  104.         fields = new Component[2];
  105.         fields[0] = retry;
  106.         fields[1] = abort;
  107.         focus = 0;
  108.         retry.requestFocus();
  109.  
  110.         show();
  111.         toFront();
  112.     }
  113.  
  114.     /**
  115.      * Processes the dialog box events
  116.      * @param e the event being handled
  117.      */
  118.     public boolean handleEvent(Event e) {
  119.         if (e.id == Event.WINDOW_DESTROY || e.arg == "Retry") {
  120.             thread.resume();
  121.             dispose();
  122.         } 
  123.         else if (e.id == Event.KEY_RELEASE) {
  124.             if ((char)e.key == '\t' || (char)e.key == '\n') {
  125.                 focus++;
  126.                 focus %= fields.length;
  127.                 fields[focus].requestFocus();
  128.             }
  129.         }
  130.         else if (e.arg == "Abort") {
  131.             Frame f = (Frame)(applet.getParent());
  132.             f.dispose();
  133.             dispose();
  134.             thread.resume();
  135.             applet.destroy();
  136.         }
  137.         return false;
  138.     }
  139. }
  140.