Message dialog box is used to display informative messages to the user. In this section we will use JOptionPane class to display the message Dialog box. Our program display "Click Me" button on the window and when user clicks on it program displays Message box with "OK" button and message "Roseindia.net".
When you run the program following window will be displayed:
When you click on "Click Me" button, following Message is displayed:
In non-swing application we were using System.in class for input or output some text or numeric values but now in the swing application we can use JOptionPane to show the output or show the message. This way of inputting or outputting works very efficiently in the Swing Applications. The window for showing message for input or output makes your application very innovative.
JOptionPane class is available in the javax.swing.*; package. This class provide various types of message dialog box as follows:
The JOptionPane class has three methods as follows:
How program Works:
This program illustrates you how to show a message dialog box when you click on the button.
This method is used to show a message dialog box which contains some text messages. This is being used with two arguments in the program where the first argument is the parent object in which the dialog box opens and another is the message which has to be shown.
Here is the code of the program:
Recommend the tutorial