Java GUI Tutorial - Output result on Dialog Box using JOptionPane.showMessageDialog() method
Coding River
Java GUI Tutorial - Output result on Dialog Box using JOptionPane.showMessageDialog() method
In the previous video, we saw how to use an input dialog box. In this video, we will now have a look at the output dialog box and the method showMessageDialog() As a reminder, the method showMessageDialog belongs to the predefined class JOptionPane which is contained in the javax.swing package
So, here is the syntax of the showMessageDialog method
JOptionPane.showMessageDialog(null, "Hello World!", "Greetings", 1);
As you can notice, the method showMessageDialog takes four 4 parameters
The first parameter is called parentComponent and it represents the parent of the dialog box. If there is no specified parent component then this parameter will be null
The second parameter represents the message to appear in the dialog box
The third parameter is the title of the dialog box
And the fourth parameter represents the MessageType and it can either be an integer value representing the type of icon that will appear in the dialog box or you can use certain JOptionPane options like For example JOptionPane.showMessageDialog(null, "Hello World!", "Greetings", JOptionPane.INFORMATION_MESSAGE);
Now if you run, notice the title, the message and the icon denoting the message type. When you click on OK, the dialog box disappears
JOptionPane.showMessageDialog(null, "Hello World!", "Greetings", JOptionPane.PLAIN_MESSAGE);
So, guys that’s how you can output results in your program using dialog box or graphical User Interface
Thanks for viewing, I hope this video was informative and do not forget to subscribe
#codingriver #java #programming ... https://www.youtube.com/watch?v=oQJFeUBOljM
7493262 Bytes