GUI Introduction


11.1 Introduction
A graphical user interface (GUI) presents a user-friendly mechanism for interacting with
an application. A GUI (pronounced “GOO-ee”) gives an application a distinctive “look”
and “feel.” Providing different applications with consistent, intuitive user interface components
allows users to be somewhat familiar with an application, so that they can learn it
more quickly and use it more productively.

As an example of a GUI, Fig. 11.1 contains an Internet Explorer web-browser
window with some of its GUI components labeled. At the top is a title bar that contains
the window’s title. Below that is a menu bar containing menus (File, Edit, View, etc.).




Below the menu bar is a set of buttons that the user can click to perform tasks in Internet
Explorer. Below the buttons is a combo box; the user can type into it the name of a website
to visit or can click the down arrow at the right side of the box to select from a list of sites
previously visited. The menus, buttons and combo box are part of Internet Explorer’s
GUI. They enable you to interact with Internet Explorer.
GUIs are built from GUI components. These are sometimes called controls or widgets—
short for window gadgets—in other languages. A GUI component is an object with
which the user interacts via the mouse, the keyboard or another form of input, such as
voice recognition. In this chapter and Chapter 22, GUI Components: Part 2, you will
learn about many of Java’s GUI components. [Note: Several concepts covered in this
chapter have already been covered in the optional GUI and Graphics Case Study of
Chapters 3–10. So, some material will be repetitive if you read the case study. You do not
need to read the case study to understand this chapter.]
11.2 Simple GUI-Based Input/Output with JOptionPane
The applications in Chapters 2–10 display text at the command window and obtain input
from the command window. Most applications you use on a daily basis use windows or
dialog boxes (also called dialogs) to interact with the user. For example, e-mail programs
allow you to type and read messages in a window provided by the e-mail program. Typically,
dialog boxes are windows in which programs display important messages to the user
or obtain information from the user. Java’s JOptionPane class (package javax.swing) provides
prepackaged dialog boxes for both input and output. These dialogs are displayed by
invoking static JOptionPane methods. Figure 11.2 presents a simple addition application
that uses two input dialogs to obtain integers from the user and a message dialog to
display the sum of the integers the user enters.

Comments

Popular posts from this blog

NICOSIA