Understanding Events

   

Java™ 2 Primer Plus
By Steven Haines, Steve Potts

Table of Contents
Chapter 14.  Event Delegation Model


When you move the mouse, press a mouse button, release a mouse button, or strike a key on the keyboard, an electrical signal is created and sent through a wire to a hardware port on your computer. Programs called device drivers that notice that these signals have been received are monitoring these hardware ports. These drivers are responsible for translating that hardware signal into a kind of message called an event. The driver hands the event to the operating system for processing.

An operating system (OS) handles two types of events: those directed at the operating system itself, and those directed at some program running under the OS.

The OS handles any events that are directed at it. (A Windows Ctrl-Alt-Delete key sequence is an example of an instruction to the operating system.) All other events are placed in a special queue, called the event queue, where programs can look and see if anything pertaining to them has happened.

One of the programs that looks at this event queue is the Java Virtual Machine (JVM). The JVM, sometimes called the Java Interpreter, is a program written in a compiled language that can talk to the operating system directly. The JVM looks at each message that comes into the queue to see if it could potentially pertain to any of the Java programs that are currently running. When it finds one of these events, it translates it into one or more java.awt.Event objects and hands that event to all programs that are listening for it.

Figure 14.1 shows this process graphically.

Figure 14.1. The Java Virtual Machine is responsible for communicating the occurrence of events to Java programs.

graphics/14fig01.gif

The JVM monitors the event queue to findevents of interest to the Java Programs running in it. How the JVM communicates these events to these programs is the subject of the next section.


       
    Top
     



    Java 2 Primer Plus
    Java 2 Primer Plus
    ISBN: 0672324156
    EAN: 2147483647
    Year: 2001
    Pages: 332

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net