Java Reference
In-Depth Information
11 Building graphical user interfaces
Main concepts discussed in this chapter:
constructing GUIs
interface components
GUI layout
event handling
Java constructs discussed in this chapter:
JFrame , JLabel , JButton , JMenuBar , JMenu , JMenuItem , ActionEvent , Color ,
FlowLayout , BorderLayout , GridLayout , BoxLayout , Box , JOptionPane ,
EtchedBorder , EmptyBorder , anonymous inner classes, final variables
So far in this topic, we have concentrated on writing applications with text-based interfaces.
The reason is not that text-based interfaces have any great advantage in principle; they just have
the one advantage that they are easier to create.
We did not want to distract too much attention from the important software-development issues
in the early stages of learning about object-oriented programming. These were issues such as
object structure and interaction, class design, and code quality.
Graphical user interfaces (GUIs) are also constructed from interacting objects, but they have
a very specialized structure, and we avoided introducing them before discussing object struc-
tures in more general terms. Now, however, we are ready to have a look at the construction
of GUIs.
GUIs give our applications an interface consisting of windows, menus, buttons, and other
graphical components. They make the applications look much more like the “typical” applica-
tion most people are used to nowadays.
Note that we are stumbling about the double meaning of the word interface again here. The
interfaces we are talking about now are neither interfaces of classes nor the Java interface con-
struct. We are now talking about user interfaces —the part of an application that is visible on
screen for the user to interact with.
Once we know how to create GUIs with Java, we can develop much better-looking programs.
Search WWH ::

Custom Search