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

  1. /*
  2.  * @(#)ClientApplet.java
  3.  */
  4.  
  5. package games.Battle.client.ClientApplet;
  6.  
  7. import java.awt.*;
  8.  
  9. /**
  10.  * This class is a simple animation thread which displays a 
  11.  * "please wait" animated graphic while the client and server
  12.  * establish communication with each other at the beginning of 
  13.  * a game.
  14.  *
  15.  * The ClientCommLink execution has absolutely no mercy with
  16.  * repect to whatever currently exists in the graphic display
  17.  * of the component it is contructed with. When started, the
  18.  * runnable will simply continually write over the entire client
  19.  * area.
  20.  *
  21.  * @author Alex Nicolaou
  22.  * @author Jay Steele
  23.  */
  24. public class ClientCommLink implements Runnable {
  25.     Component comp;
  26.  
  27.     static String[] msg = { "Please wait as a subspace commlink is",
  28.                             "established with orbiting satellite..." };
  29.  
  30.     /** 
  31.      * Construct a ClientCommLink class, using the given component
  32.      * to draw itself in.
  33.      */
  34.     public ClientCommLink(Component c) {
  35.         comp = c;
  36.     }
  37.  
  38.     /**
  39.      * The run method for the ClientCommLink instance, executed when
  40.      * a controlling thread is started. This method simply loops 
  41.      * forever (until it is killed) display its contents and
  42.      * doing its animation.
  43.      */
  44.     public void run() {
  45.         Graphics g = comp.getGraphics();
  46.         Rectangle b = comp.bounds();
  47.  
  48.         // g.setFont( ? );
  49.         
  50.         FontMetrics fm = g.getFontMetrics();
  51.  
  52.         // Determine the height of the font, and the total height
  53.         // of the message
  54.         int fh = fm.getHeight();
  55.         int h = fh * msg.length;
  56.  
  57.         // determine the widths of each individual message
  58.         int[] sw = new int[msg.length];
  59.         for (int i=0; i<msg.length; i++) {
  60.             sw[i] = fm.stringWidth(msg[i]);
  61.         }
  62.  
  63.         int count = 0;
  64.         while (true) {
  65.  
  66.             double cx = (double)b.width / 2.0;
  67.             double cy = (double)b.height / 2.0;
  68.  
  69.             // clear the background
  70.             g.setColor(Color.black);
  71.             g.fillRect(0, 0, b.width, b.height);
  72.  
  73.             // write the text, centered in the component
  74.             g.setColor(Color.white);
  75.             int x, y;
  76.             int starty = (int)(cy - (double)fh/2.0);
  77.             for (int i=0; i<msg.length; i++) {
  78.                 x = (int)(cx - (double)sw[i]/2.0);
  79.                 y = starty + i * fh;
  80.  
  81.                 g.drawString(msg[i], x, y);
  82.             }
  83.  
  84.             int lightDist = 200;
  85.             int numLights = 10;
  86.             int lightDelta = (int)((double)lightDist / (double)numLights);
  87.             int startLightX = (int)(cx - (double)lightDist / 2.0);
  88.             int startLightY = (int)(starty + h + 20);
  89.  
  90.             g.setColor(new Color(255, 0, 25*count));
  91.             g.fillOval(startLightX+(count*lightDelta), startLightY,
  92.                             10, 10);
  93.  
  94.             count = count + 1;
  95.             count = count % numLights;
  96.  
  97.             try {
  98.                 Thread.currentThread().sleep(100);
  99.             } catch (Exception e) {}
  100.         }
  101.     }
  102. }
  103.