home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap32 / ThreadApplet5.java < prev   
Encoding:
Java Source  |  1996-03-22  |  1.3 KB  |  65 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3. import ColorThread;
  4.  
  5. public class ThreadApplet5 extends Applet
  6. {
  7.     ColorThread thread;
  8.     Color color1;
  9.     Color color2;
  10.     Color color3;
  11.     Font font;
  12.  
  13.     public void init()
  14.     {
  15.         Button button = new Button("Close");
  16.         add(button);
  17.     }
  18.  
  19.     public void start()
  20.     {
  21.         color1 = Color.red;
  22.         color2 = Color.green;
  23.         color3 = Color.blue;
  24.  
  25.         thread = new ColorThread(this);
  26.         thread.start();
  27.     }
  28.  
  29.     public void stop()
  30.     {
  31.         thread.stop();
  32.     }
  33.  
  34.     public void paint(Graphics g)
  35.     {
  36.         g.setColor(color1);
  37.         g.fillRect(30, 50, 50, 100);
  38.         g.setColor(color2);
  39.         g.fillRect(100, 50, 50, 100);
  40.         g.setColor(color3);
  41.         g.fillRect(170, 50, 50, 100);
  42.     }
  43.     public boolean action(Event evt, Object arg)
  44.     {
  45.         if (arg == "Close")
  46.             System.exit(0);
  47.  
  48.         return true;
  49.     }
  50.  
  51.     public static void main(String args[])
  52.     {
  53.         ThreadApplet5 app = new ThreadApplet5();
  54.         Frame frame = new Frame("Color Window");
  55.  
  56.         app.init();
  57.         app.start();
  58.  
  59.         frame.add("Center", app);
  60.         frame.resize(260, 300);
  61.         frame.show();
  62.     }
  63. }
  64.  
  65.