Java Reference
In-Depth Information
Chapter 14
Graphical User Interfaces
Introduction
14.1 GUI Basics
Graphical Input and Output
with Option Panes
In this chapter we will explore the creation of graphical user interfaces
(GUIs).Although console programs like the ones we have written in the
preceding chapters are still very important, the majority of modern desk-
top applications have graphical user interfaces. Supplement 3G introduced
a DrawingPanel class that allowed you to draw two-dimensional graph-
ics on the screen.This class is useful for certain applications, but writing a
GUI is not the same as drawing shapes and lines onto a canvas. A real
graphical user interface includes window frames which you create that
contain buttons, text input fields, and other onscreen components.
Working with Frames
Buttons, Text Fields, and Labels
Changing a Frame's Layout
Handling an Event
14.2 Laying Out Components
Layout Managers
Composite Layouts
14.3 Interaction between
Components
Example 1: BMI GUI
A major part of creating a graphical user interface in Java is figuring out
how to position and lay out the components of the user interface to
match the appearance you desire. Once you have chosen and laid out
these components, you must make the events interactive by making them
respond to various user events such as button clicks or mouse move-
ments.There are many predefined components, but you can also define
components that draw custom two-dimensional graphics, including anima-
tions. At the end of this chapter, we will reimplement a basic version of
the DrawingPanel class from Supplement 3G.
Object-Oriented GUIs
Example 2: Credit Card GUI
14.4 Additional Components
and Events
Text Areas, Scrollbars, and Fonts
Icons
Mouse Events
14.5 Two-Dimensional
Graphics
Drawing onto Panels
Animation with Timers
14.6 Case Study: Implementing
DrawingPanel
Initial Version without Events
Second Version with Events
822
 
Search WWH ::




Custom Search