14.3 Simple GUI-Based Input/Output with JOptionPane
The applications in Chapters 2–10 display text in 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, an e-mail program allows you to type and read messages in a window the program provides. 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 prebuilt dialog boxes for both input and output. These are displayed by invoking static JOptionPane
methods. Figure 14.2 presents a simple addition application that uses two input dialogs
Get Java How to Program (early objects), 9/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.