home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / EventDispatchThread.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  1.6 KB  |  61 lines

  1. /*
  2.  * @(#)EventDispatchThread.java    1.18 98/03/18
  3.  *
  4.  * Copyright 1996, 1997 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt;
  16.  
  17. /**
  18.  * EventDispatchThread is a package-private AWT class which takes
  19.  * events off the EventQueue and dispatches them to the appropriate
  20.  * AWT components.
  21.  *
  22.  * @version 1.18 03/18/98
  23.  * @author Tom Ball
  24.  * @author Amy Fowler
  25.  */
  26. class EventDispatchThread extends Thread {
  27.     private EventQueue theQueue;
  28.     private boolean doDispatch = true;
  29.  
  30.     EventDispatchThread(String name, EventQueue queue) {
  31.     super(name);
  32.         theQueue = queue;
  33.     }
  34.  
  35.     public void stopDispatching() {
  36.         doDispatch = false;
  37.     }
  38.  
  39.     public void run() {
  40.        while (doDispatch) {
  41.             try {
  42.                 AWTEvent event = theQueue.getNextEvent();
  43.                 theQueue.dispatchEvent(event);
  44.             } catch (ThreadDeath death) {
  45.                 return;
  46.  
  47.             } catch (Throwable e) {
  48.                 System.err.println(
  49.                     "Exception occurred during event dispatching:");
  50.                 e.printStackTrace();
  51.             }
  52.         }
  53.     }
  54.  
  55.     boolean isDispatching(EventQueue eq) {
  56.     return theQueue.equals(eq);
  57.     }
  58.  
  59.     EventQueue getEventQueue() { return theQueue; }
  60. }
  61.