Java Reference
In-Depth Information
EXAMPLE 3-11
Consider the following statements:
String str;
int
num1 = 45;
int
num2 = 56;
int
sum;
3
str = "The two numbers are: " + num1 + " and " + num2 + "\n";
sum = num1 + num2;
str = str + "The sum of the numbers is: " + sum
+ "\n";
str = str + "That is all for now!";
Figure 3-11 shows the output of the statement:
JOptionPane.showMessageDialog(
null
, str, "Summing Numbers",
JOptionPane.ERROR_MESSAGE);
FIGURE 3-11
Message dialog box showing the output of the string
str
The
class
JOptionPane
is contained in the
package
javax.swing
. Therefore, to use this
class
in a program, the program must import it from the
package
javax.swing
.The
following statements illustrate how to import the
class
JOptionPane
(you can use either
format):
import
javax.swing.JOptionPane;
or:
import
javax.swing.*;
System.exit
In order to use the input/output dialog boxes and properly terminate program execution,
the program must include the following statement:
System.exit(0);
Search WWH ::
Custom Search