home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / windows / doc / applet / overview / betaclasses / good.java < prev    next >
Encoding:
Java Source  |  1996-02-26  |  2.1 KB  |  72 lines

  1. /*
  2.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. import java.awt.Graphics;
  18.  
  19. public class Good extends java.applet.Applet implements Runnable {
  20.     static final int NUMLOOPS = 2000000;
  21.     int loop = 0;
  22.     boolean doneInitializing = false;
  23.     String message = null;
  24.     Thread loopThread = null;
  25.  
  26.     public void init() {
  27.     resize(500, 20);
  28.     }
  29.  
  30.     public void start() {
  31.     if (loopThread == null) {
  32.         loopThread = new Thread(this, "Good thread");
  33.     } else { //reset and do it again
  34.         loop = 0;
  35.         doneInitializing = false;
  36.         message = null;
  37.     }
  38.     loopThread.start();
  39.     }
  40.  
  41.     public void stop() {
  42.     loopThread.stop();
  43.     loopThread = null;
  44.     }
  45.  
  46.     public void run() {
  47.     while (loop < NUMLOOPS) {
  48.         if ((++loop%50000)==0) {
  49.         message = "Good: Initialization loop #"
  50.               + loop + " of " + NUMLOOPS;
  51.         getAppletContext().showStatus(message);
  52.         repaint();
  53.         Thread.yield();
  54.         }
  55.     }
  56.     doneInitializing = true;
  57.     repaint();
  58.     }
  59.  
  60.  
  61.     /* The paint() method can't be called until init() has exited. */
  62.     public void paint(Graphics g) {
  63.     g.drawRect(0, 0, size().width - 1, size().height - 1);
  64.     if (message == null) 
  65.         g.drawString("Good: ", 5, 15);
  66.     else if (!doneInitializing) 
  67.         g.drawString(message, 5, 15);
  68.     else 
  69.         g.drawString("Good: Done initializing.", 5, 15);
  70.     }
  71. }
  72.