Java Reference
In-Depth Information
3.6 (Optional) GUI and Graphics Case Study: Using
Dialog Boxes
This optional case study is designed for those who want to begin learning Java's powerful
capabilities for creating graphical user interfaces (GUIs) and graphics early in the topic,
before the deeper discussions of these topics later in the topic. This case study features
Java's mature Swing technology, which as of this writing is still a bit more popular than
the newer JavaFX technology presented in later chapters.
This GUI and Graphics Case Study appears in 10 brief sections (see Fig. 3.11). Each
section introduces new concepts and provides examples with screen captures that show
sample interactions and results. In the first few sections, you'll create your first graphical
apps. In subsequent sections, you'll use object-oriented programming concepts to create
an app that draws a variety of shapes. When we formally introduce GUIs in Chapter 12,
we use the mouse to choose exactly which shapes to draw and where to draw them. In
Chapter 13, we add capabilities of the Java 2D graphics API to draw the shapes with dif-
ferent line thicknesses and fills. We hope you find this case study informative and enter-
taining.
Location
Title—Exercise(s)
Section 3.6
Using Dialog Boxes—Basic input and output with dialog boxes
Section 4.15
Creating Simple Drawings—Displaying and drawing lines on the
screen
Section 5.11
Drawing Rectangles and Ovals—Using shapes to represent data
Section 6.13
Colors and Filled Shapes—Drawing a bull's-eye and random graphics
Section 7.17
Drawing Arcs—Drawing spirals with arcs
Section 8.16
Using Objects with Graphics—Storing shapes as objects
Section 9.7
Displaying Text and Images Using Labels—Providing status
information
Section 10.10
Drawing with Polymorphism—Identifying the similarities between
shapes
Exercise 12.17
Expanding the Interface—Using GUI components and event handling
Exercise 13.31
Adding Java 2D—Using the Java 2D API to enhance drawings
Fig. 3.11 | Summary of the GUI and Graphics Case Study in each chapter.
Displaying Text in a Dialog Box
The programs presented thus far display output in the command window . Many apps use
windows or dialog boxes (also called dialogs ) to display output. Web browsers such as
Chrome, Firefox, Internet Explorer, Safari and Opera display web pages in their own win-
dows. E-mail programs allow you to type and read messages in a window. Typically, dialog
boxes are windows in which programs display important messages to users. Class JOption-
Pane provides prebuilt dialog boxes that enable programs to display windows containing
messages—such windows are called message dialogs . Figure 3.12 displays the String
"Welcome to Java" in a message dialog.
 
 
Search WWH ::




Custom Search