Java GUI Tutorial - Output result on Dialog Box using JOptionPane.showMessageDialog() method

preview_player
Показать описание

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()

So, here is the syntax of the showMessageDialog method

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.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.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
Рекомендации по теме
Комментарии
Автор

Thank you. However, I was wondering about the first null. Is there a way you can put in a value or values so that the JOption pane itself can appear at a random area on the screen rather than the dead center of the screen?

MvpMartell
Автор

I am running MAC OS when I try to close out the JOptionPane nothing happens.

Rizzgurl