Introduction To GUI Programming
Introduction To GUI Programming
Introduction To GUI Programming
Programming
Chapter Topics
Event-driven programming
Graphical user interfaces
The three parts of a GUI
GUI components
Containers
The Abstract Windowing Toolkit (AWT)
How the AWT relates to Swing
Swing class hierarchy
Swing and the AWT
A graphical user interface consists
of graphical components, such as:
Windows
Buttons
Menus
Text fields
Swing and the AWT
Swing components are based on the fundamental classes of
the Application Windowing Toolket (AWT).
The AWT also contains some older components which are no
longer used.
Swing components come with recent java Java releases.
Swing integrates smoothly with the Java Foundation Classes.
The Java Foundation Classes provide many classes needed for
modern software development.
Events
A GUI application program shows the user a graphical interface
containing several graphical components. The user controls the
application by interacting with the graphical components, doing such
things as:
Clicking on a button to choose a program option.
Making a choice from a menu.
Entering text in a text field.
Dragging a scroll bar.
An action such as clicking on a button is called an event. In reading
these notes you have been generating events by using the graphical
interface of your Web browser.
Events-driven Programming
When you perform an action on a graphical component you generate
an event. In event-driven programming the program responds to
these events. The order of the events is determined by the user, not the
program.
For example, you can generate an event by clicking on this button:
Generate an Event, Or you could click on this button: Generate
another Event Click on the buttons a few more times in any order.
The program (your Web browser, in this case) is event-driven and
responds to the events in whatever order you generate them.
Responding to Events
Three Parts of a GUI Program
A GUI program has three parts:
The JComponent class is derived
from Container and is one of
the base classes of Swing.
The JFrame class is derived from
the AWT Frame class. It is usually
the main container for a GUI
application.
The JApplet class is derived from
the AWT Applet class and is used
for modern applets.