home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap31 / ThreadApplet6.java < prev   
Encoding:
Java Source  |  1996-03-21  |  1.1 KB  |  52 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3. import ColorThread2;
  4. import ColorThread3;
  5.  
  6. public class ThreadApplet6 extends Applet
  7. {
  8.     ColorThread2 thread1;
  9.     ColorThread3 thread2;
  10.     Color color1;
  11.     Color color2;
  12.     Color color3;
  13.     Font font;
  14.  
  15.     public void start()
  16.     {
  17.         color1 = Color.red;
  18.         color2 = Color.green;
  19.         color3 = Color.blue;
  20.  
  21.         thread1 = new ColorThread2(this);
  22.         thread1.start();
  23.         thread2 = new ColorThread3(this);
  24.         thread2.start();
  25.     }
  26.  
  27.     public void stop()
  28.     {
  29.         thread1.stop();
  30.         thread2.stop();
  31.     }
  32.  
  33.     public void paint(Graphics g)
  34.     {
  35.         g.setColor(color1);
  36.         g.fillRect(30, 50, 50, 100);
  37.         g.setColor(color2);
  38.         g.fillRect(100, 50, 50, 100);
  39.         g.setColor(color3);
  40.         g.fillRect(170, 50, 50, 100);
  41.     }
  42.  
  43.     synchronized public void SetColors(Color color1, Color color2, Color color3)
  44.     {
  45.         this.color1 = color1;
  46.         this.color2 = color2;
  47.         this.color3 = color3;
  48.         repaint();
  49.     }
  50. }
  51.  
  52.