home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap31 / ColorThread.java < prev    next >
Text File  |  1996-03-21  |  1KB  |  49 lines

  1. import java.awt.Color;
  2.  
  3. public class ColorThread extends Thread
  4. {
  5.     ThreadApplet5 applet;
  6.     int count;
  7.  
  8.     ColorThread(ThreadApplet5 applet)
  9.     {
  10.         this.applet = applet;
  11.     }
  12.  
  13.     public void run()
  14.     {
  15.         while (true)
  16.         {
  17.             if (applet.color1 == Color.red)
  18.             {
  19.                 applet.color1 = Color.blue;
  20.                 applet.color2 = Color.red;
  21.                 applet.color3 = Color.green;
  22.             }
  23.             else if (applet.color1 == Color.blue)
  24.             {
  25.                 applet.color1 = Color.green;
  26.                 applet.color2 = Color.blue;
  27.                 applet.color3 = Color.red;
  28.             }
  29.             else
  30.             {
  31.                 applet.color1 = Color.red;
  32.                 applet.color2 = Color.green;
  33.                 applet.color3 = Color.blue;
  34.             }
  35.  
  36.             applet.repaint();
  37.  
  38.             try
  39.             {
  40.                 sleep(100);
  41.             }
  42.             catch (InterruptedException e)
  43.             {
  44.             }
  45.         }
  46.     }
  47. }
  48.  
  49.