Page 679 - Introduction to Programming with Java: A Problem Solving Approach
P. 679
16.14 DistinguishingBetweenMultipleEvents
16.15 UsinggetActionCommandtoDistinguishBetweenMultipleEvents
16.16 Color
16.17 How GUI Classes Are Grouped Together
16.18 Mouse Listeners and Images (Optional)
16.1 Introduction
Hopefully, you’ve been on the edge of your seat in reading the prior chapters. If not, be prepared to be on the edge of your seat now. It’s time for the really good stuff, graphical user interface (GUI ) programming.
You’ve probably heard the term GUI, and you probably know that it’s pronounced “gooey.” But do GUI’s three words, Graphical User Interface, make sense? “Graphical” refers to pictures, “user” refers to a person, and “interface” refers to communication. Thus, GUI programming employs pictures—like win- dows, text boxes, buttons, and so on—to communicate with users. For example, Figure 16.1 shows a window with a text box and a button. We’ll describe windows, text boxes, and buttons in detail later on.
Figure 16.1 Example window that uses a text box and a button
In the old days, program interfaces consisted of just text. Programs would prompt the user with a text question, and users would respond with a text answer. That’s what we’ve been using for all of our programs so far. Text input/output (I/O) works well in many situations, but you can’t get around the fact that some people consider text display to be boring. Many of today’s users expect programs to be livelier. They expect windows, buttons, colors, and so on for input and output. They expect GUI.
Although companies still write many text-based programs for internal use, they normally write GUI- based programs for programs that are to be used externally. It’s important for external programs to be GUI based because external programs go to customers, and customers typically won’t buy programs un- less they are GUI based. So if you want to write programs that people will buy, you’d better learn GUI programming.
We start this chapter with an overview of basic GUI concepts and terminology. We then move on to a bare-bones program where we introduce basic GUI syntax. We next cover listeners, inner classes, and several rudimentary GUI components, which are objects that sit inside a window, including JLabel, JTextField, and JButton. Finally, we cover the JOptionPane class (for generating a dialog box) and the Color class (for generating a color).
You may have noticed optional GUI-track sections at the end of about half of the prior chapters. The GUI material in this chapter and the next is different from the GUI material in the earlier chapters, and it does not depend on the earlier chapters’ GUI material. So if you skipped the earlier GUI material, no worries.
16.1 Introduction 645
Apago PDF Enhancer
button
text box