19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

(a)<br />

(b)<br />

Figure 38.10<br />

(a) A JOptionPane dialog can display an icon, a message, an input, and<br />

option but<strong>to</strong>ns. (b) The message dialog displays a message and waits for<br />

the user <strong>to</strong> click OK.<br />

For example, you can use the following method <strong>to</strong> create a message<br />

dialog box,as shown in Figure 38.10(b):<br />

JOptionPane.showMessageDialog(null, "SSN not found",<br />

"For Your Information", JOptionPane.INFORMATION_MESSAGE);<br />

38.6.1 Message Dialogs<br />

A message dialog box displays a message that alerts<br />

the user and waits for the user <strong>to</strong> click the OK but<strong>to</strong>n<br />

<strong>to</strong> close the dialog. The methods for creating message<br />

dialogs are:<br />

public static void showMessageDialog(Component parentComponent,<br />

Object message)<br />

public static void showMessageDialog(Component parentComponent,<br />

Object message,<br />

String title,<br />

int messageType)<br />

public static void showMessageDialog(Component parentComponent,<br />

Object message,<br />

String title,<br />

int messageType,<br />

Icon icon)<br />

The parentComponent can be any <strong>com</strong>ponent or null. The message is<br />

an object, but often a string is used. These two parameters must<br />

always be specified. The title is a string displayed in the title<br />

bar of the dialog with the default value "Message”.<br />

The messageType is one of the following constants:<br />

JOptionPane.ERROR_MESSAGE<br />

JOptionPane.INFORMATION_MESSAGE<br />

JOptionPane.PLAIN_MESSAGE<br />

JOptionPane.WARNING_MESSAGE<br />

JOptionPane.QUESTION_MESSAGE<br />

By default, messageType is JOptionPane.INFORMATION_MESSAGE. Each<br />

type has an associated icon except the PLAIN_MESSAGE type, as<br />

shown in Figure 38.11. You can also supply your own icon in the<br />

icon parameter.<br />

19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!