Page 130 - Introduction to Programming with Java: A Problem Solving Approach
P. 130
96 Chapter 3 Java Basics
Figure 3.16 A dialog box that displays installation information
to find it. You do that by importing the JOptionPane class into your program. More specifically, you need
to include this import statement at the top of your program: import java.util.JOptionPane;
See the InstallationDialog program in Figure 3.17. It produces the dialog box shown in Figure 3.16. The In- stallationDialog program’s code should look familiar. At the top, it has the JOptionPane import state- ment. Then it has the standard class heading, standard main method heading, and braces. What’s new is the JOptionPane.showMessageDialog method call.
/********************************************************
*
InstallationDialog.java
*
Dean & Dean
Apago PDF Enhancer
*
*
This program illustrates JOptionPane's message dialog.
********************************************************/
import javax.swing.JOptionPane;
public class InstallationDialog
{
}
public static void main(String[] args)
{
}
JOptionPane.showMessageDialog(null,
"Before starting the installation, " +
"shut down all applications.");
// end class InstallationDialog
Figure 3.17 InstallationDialog program
The showMessageDialog method displays a message in a dialog box. Here’s the syntax for calling
the showMessageDialog method: JOptionPane.showMessageDialog(null, <message>)
The showMessageDialog method takes two arguments. The first argument specifies the position of the dialog box on the computer screen. We’ll keep things simple and go with the default position, which is the