next up previous
Next: 3.1.1 Model-View-controller Pattern Up: 3. Graphical User Interfaces Previous: 3. Graphical User Interfaces

3.1 GUI Programming

Graphical user interface programming is inherently more complex than ordinary applications programming because the graphical interface computation is driven by a stream of graphical input actions. All of the input actions performed by a program user including moving the mouse, clicking a mouse button, and typing a keystroke are processed by code in the computer operating system. This code determines when an input action of potential interest to the application occurs. Such an input action is called an ``event''. Typically mouse movement alone does not constitute an event; the operating system updates the position of the cursor on the screen as the mouse is moved. When a mouse button is clicked or a key is typed, the operating system interrupts the application program and informs it that the specified event has occurred. The Java virtual machine includes an event monitor that processes these interruptions. This event processing code filters input events just as the operating system code filters inputs. For some events such as typing a key (other than return), the Java event monitor simply echoes the character on the screen in the appropriate place. For other events such as a mouse click on a button, the Java event monitor generates a program Event object that it places on a queue of pending Events for processing by the running Java program.

Every Java program that creates graphical components has an extra thread of execution that processes the program Event objects in the event queue. For each program Event object, the thread calls the ``listener'' method that has been registered by the Java program for handling this kind of program event.



 
next up previous
Next: 3.1.1 Model-View-controller Pattern Up: 3. Graphical User Interfaces Previous: 3. Graphical User Interfaces
Corky Cartwright
2000-01-07