Burt Reynolds Burt Reynolds - 2 months ago 51
Java Question

Does the JOptionPane showMessageDialog method automatically instantiate the objects needed for this dialogue box

I know when we use the JOptionPane class, we don't have to instantiate it as this class was designed to make quick simple on the fly dialogue boxes. Does the

showMessageDialog method
automatically instantiate the objects needed for this dialogue box?

Answer

Yes, JOptionPane#showMessageDialog creates all of the necessary components and bits necessary to display the dialog boxes. If it didn't, it wouldn't be a very good method.

One can think of this method as a factory method; if you give it certain parameters it has a duty of producing an interface which fills in those values in specific locations. This factory method handles the creation of the GUI components necessary to work, and thus the end user doesn't need to worry about it.

...But if the end user really wants to worry about it, they're more than welcome to go down the rabbit hole if they want to.