Java Reference
In-Depth Information
whether a file we want to open really exists. If writing an application for seri-
ous purposes, you have to insert these tests. Also, exceptions are not used to
cope with errors; for some errors a message will be displayed on the console.
When writing a larger application, it is advisable to make use of Java's exception
mechanism.
The author is grateful for any corrections and suggestions. Please do not hesi-
tate to report typographical errors or to point out parts that appear unclear. Also
tell me if you would like to see an example of something specific or if there are
any problems concerning the example programs. If the reader is looking for a spe-
cial component or a feature of a component that is not explained in the topic,
you should first consult the Java documentation. Answers to frequently asked
questions and program updates will also be placed on the topic's home page. The
author's address is
Paul Fischer
IMM, Technical University of Denmark
Building 322
DK-2800 Kgs. Lyngby
Denmark
email paf@imm.dtu.dk
1.2
How graphical interfaces work
Programs with graphical user interfaces (GUIs) are event driven . This means that
the program reacts to actions of the user; these actions are called events . Examples
of events are pressing a key, moving the mouse, pressing a button and selecting a
menu item.
A program with a GUI has a (short) start-up phase in which the GUI is con-
structed but not yet displayed. Some other preparations (not related to graphics)
are also performed. This phase is not event driven and user interaction is not
possible. After this phase the GUI is displayed on the screen and the program is
now controlled by events.
Of course, we want the program to react only to a few types of event, not all. The
programmer has to specify those events to which the program has to react and, of
course, what the reaction should be. In Java this is done by implementing so-called
listeners which wait for specific kinds of events to occur. Once the programmer
has implemented a listener for a specific type of event, the runtime system will
automatically inform the listener when such an event occurs. The listener then
performs the desired action. Events are processed in the order of their occurrence.
There are many types of event in Java, associated with the different event
sources, such as buttons, menus or the mouse. Events contain information on
what has happened, e.g. what triggered the event (a button, a menu) and where it
occurred (the coordinates of the mouse). This information is then exploited by the
listener.
Search WWH ::




Custom Search