home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / WDESAMPL.BIN / NervousText.java < prev    next >
Text File  |  1997-04-01  |  3KB  |  108 lines

  1. /*
  2.  * @(#)NervousText.java    1.1 97/04/01
  3.  *
  4.  * Copyright (c) 1994-1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  *
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  *
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30.  
  31. /*  Daniel Wyszynski 
  32.     Center for Applied Large-Scale Computing (CALC) 
  33.     04-12-95 
  34.  
  35.     Test of text animation.
  36.  
  37.     kwalrath: Changed string; added thread suspension. 5-9-95
  38. */
  39. import java.awt.Graphics;
  40. import java.awt.Font;
  41.  
  42. public class NervousText extends java.applet.Applet implements Runnable {
  43.  
  44.     char separated[];
  45.     String s = null;
  46.     Thread killme = null;
  47.     int i;
  48.     int x_coord = 0, y_coord = 0;
  49.     String num;
  50.     int speed=35;
  51.     int counter =0;
  52.     boolean threadSuspended = false; //added by kwalrath
  53.  
  54. public void init() {
  55.     s = getParameter("text");
  56.     if (s == null) {
  57.         s = "HotJava";
  58.     }
  59.  
  60.     separated =  new char [s.length()];
  61.     s.getChars(0,s.length(),separated,0);
  62.     resize((s.length()+1)*15, 50);
  63.     setFont(new Font("TimesRoman",Font.BOLD,36));
  64.  }
  65.  
  66. public void start() {
  67.     if(killme == null) 
  68.     {
  69.         killme = new Thread(this);
  70.         killme.start();
  71.     }
  72.  }
  73.  
  74. public void stop() {
  75.     killme = null;
  76.  }
  77.  
  78. public void run() {
  79.     while (killme != null) {
  80.     try {Thread.sleep(100);} catch (InterruptedException e){}
  81.     repaint();
  82.     }
  83.     killme = null;
  84.  }
  85.  
  86. public void paint(Graphics g) {
  87.     for(i=0;i<s.length();i++)
  88.     {
  89.     x_coord = (int) (Math.random()*10+15*i);
  90.     y_coord = (int) (Math.random()*10+36);
  91.     g.drawChars(separated, i,1,x_coord,y_coord);
  92.     }
  93.  }
  94.  
  95. /* Added by kwalrath. */
  96. public boolean mouseDown(java.awt.Event evt, int x, int y) {
  97.         if (threadSuspended) {
  98.             killme.resume();
  99.         }
  100.         else {
  101.             killme.suspend();
  102.         }
  103.         threadSuspended = !threadSuspended;
  104.     return true;
  105.     }
  106. }
  107.  
  108.