home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 July & August / Pcwk78a98.iso / Internet / Javadraw / DATA.Z / EventDispatchThread.java < prev    next >
Text File  |  1997-08-30  |  3KB  |  83 lines

  1. /*
  2.  * @(#)EventDispatchThread.java    1.14 97/03/10  Amy Fowler
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.awt;
  24.  
  25. import java.awt.event.MouseEvent;
  26. import java.awt.event.KeyEvent;
  27. import java.awt.event.PaintEvent;
  28. import java.awt.peer.ActiveEvent;
  29.  
  30. /**
  31.  * EventDispatchThread is a package-private AWT class which takes
  32.  * events off the EventQueue and dispatches them to the appropriate
  33.  * AWT components.
  34.  *
  35.  * @version 1.14 03/10/97
  36.  * @author Tom Ball
  37.  * @author Amy Fowler
  38.  */
  39. class EventDispatchThread extends Thread {
  40.     private EventQueue theQueue;
  41.     private boolean doDispatch = true;
  42.  
  43.     EventDispatchThread(String name, EventQueue queue) {
  44.     super(name);
  45.         theQueue = queue;
  46.     }
  47.  
  48.     public void stopDispatching() {
  49.         doDispatch = false;
  50.     }
  51.  
  52.     public void run() {
  53.        while (doDispatch) {
  54.             try {
  55.                 AWTEvent event = theQueue.getNextEvent();
  56.                 if (false) {
  57.                     // Not until 1.2...
  58.                     // theQueue.dispatchEvent(event);
  59.                 } else {
  60.                     // old code...
  61.                     Object src = event.getSource();
  62.                     if (src instanceof Component) {
  63.                         ((Component)src).dispatchEvent(event);
  64.                     } else if (src instanceof MenuComponent) {
  65.                         ((MenuComponent)src).dispatchEvent(event);
  66.                     } else if (event instanceof ActiveEvent) {
  67.             // This could become the sole method of dispatching in time, and 
  68.             // moved to the event queue's dispatchEvent() method.
  69.             ((ActiveEvent)event).dispatch();
  70.             }
  71.                 }
  72.             } catch (ThreadDeath death) {
  73.                 return;
  74.  
  75.             } catch (Throwable e) {
  76.                 System.err.println(
  77.                     "Exception occurred during event dispatching:");
  78.                 e.printStackTrace();
  79.             }
  80.         }
  81.     }
  82. }
  83.