Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

WHAT YOU’LL LEARN IN
THIS HOUR:
.Creating user interface
components such as
buttons
.Creating labels,text fields,
and other components
.Grouping components
together
.Putting components inside
other components
.Opening and closing
windows

Things are going to get pretty gooey during this hour. You will make an
enormous mess creating your first graphical user interface (GUI) with Java.


Computer users have come to expect their software to feature a GUI, take
user input from a mouse, and work like other programs. Although some
users still work in command-line environments such as MS-DOS or a
Linux shell, most would be confused by software that does not offer a
point-and-click, drag-and-drop graphical interface like in Microsoft
Windows or MacOS.


Java supports this kind of software with Swing, a collection of Java classes
that represent all the different buttons, text fields, sliders, and other com-
ponents that can be part of a GUI, as well as the classes needed to take
user input from those components.


During this hour and the next, you create and organize GUIs in Java.
Afterward in Hour 15, “Responding to User Input,” you enable those inter-
faces to receive mouse clicks and other user input.


Swing and the Abstract Windowing


Toolkit


Because Java is a cross-platform language that enables you to write pro-
grams for many different operating systems, its graphical user software
must be flexible. Instead of catering only to the Windows style or the Mac
version, it must handle both along with other platforms.


With Java, the development of a program’s user interface is based on
Swing and an earlier set of classes called the Abstract Windowing Toolkit.
These classes enable you to create a GUI and receive input from the user.


HOUR 13


Building a Simple User Interface

Free download pdf