home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / windows / doc / applet / overview / betaclasses / printthread.000 < prev    next >
Encoding:
Text File  |  1996-02-26  |  2.0 KB  |  78 lines

  1. <!--NewPage-->
  2. <html>
  3. <head>
  4. <title>PrintThread.java</title>
  5. </head>
  6. <body>
  7. <p>
  8. <hr size=4>
  9.  
  10. <h2>
  11.     PrintThread.java
  12. </h2>
  13. <p>
  14. <blockquote>
  15.  
  16. <pre>
  17.  
  18. /*
  19.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  20.  *
  21.  * Permission to use, copy, modify, and distribute this software
  22.  * and its documentation for NON-COMMERCIAL purposes and without
  23.  * fee is hereby granted provided that this copyright notice
  24.  * appears in all copies. Please refer to the file "copyright.html"
  25.  * for further important copyright and licensing information.
  26.  *
  27.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  28.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  29.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  30.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  31.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  32.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  33.  */
  34. import java.awt.*;
  35.  
  36. public class PrintThread extends java.applet.Applet {
  37.  
  38.     TextField field = new TextField(80);
  39.  
  40.     public void init() {
  41.     field.setEditable(false);
  42.     setLayout(new BorderLayout()); //workaround for chopped off sides
  43.     add("Center", field);  
  44.     show();
  45.         addItem("init:" + Thread.currentThread().getName() + " ");
  46.     }
  47.  
  48.     public void start() {
  49.         addItem("start:" + Thread.currentThread().getName() + " ");
  50.     }
  51.  
  52.     public void stop() {
  53.         addItem("stop:" + Thread.currentThread().getName() + " ");
  54.     }
  55.  
  56.     public void destroy() {
  57.         addItem("destroy:" + Thread.currentThread().getName() + " ");
  58.     }
  59.  
  60.     public void addItem(String newWord) {
  61.     String t = field.getText();
  62.     System.out.println(newWord);
  63.     field.setText(t + newWord);
  64.     field.repaint();
  65.     }
  66.  
  67.     public synchronized void paint(Graphics g) {
  68.         addItem("paint:" + Thread.currentThread().getName() + " ");
  69.     }
  70. }
  71. </pre>
  72. </blockquote>
  73. <p>
  74. <hr size=4>
  75. <p>
  76. </body>
  77. </html>
  78.