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 windows. 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 JOptionPane 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.

 1   // Fig. 3.12: Dialog1.java 2   // Using JOptionPane ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.