Java Reference
In-Depth Information
A window-based application, or an applet come to that, is quite different. The operation of the program
is driven by what you do with the GUI. Selecting menu items or buttons using the mouse, or through
the keyboard, causes particular actions within the program. At any given moment you have a whole
range of possible interactions available to you, each of which will result in a different program action.
Until you do something, the specific program code that is to be executed next is not known.
Event-driven Programs
Your actions when you're using the GUI for a window-based program or an applet - clicking a menu
item or a button, moving the mouse and so on - are first identified by the operating system. For each
action, the operating system determines which of the programs currently running on your computer
should know about it, and passes the action on to that program. When you click a mouse button, it's the
operating system that registers this and notes the position of the mouse cursor on the screen. It then
decides which application controls the window where the cursor was when you pressed the button, and
communicates the mouse button-press to that program. The signals that a program receives from the
operating system as a result of your actions are called events .
Keystrokes, Mouse Actions
Operating System
Java Library Classes
Events
Your
Program
method
method
method
method
A program is not obliged to respond to any particular event. If you just move the mouse, for instance, the
program need not invoke any code to react to that. If it doesn't, the event is quietly disposed of. Each event
that the program does recognize is associated with one or more methods, and when the event occurs - when
you click a menu item, for example - the appropriate methods will be called automatically. A window-based
program is called an event-driven program , because the sequence of events created as a result of your
interaction with the GUI drives and determines what happens in the program.
 
 
 
 
 
Search WWH ::




Custom Search