Message dialogs provide information to the user. Message dialogs are created with the JOptionPane.showMessageDialog() method.
We call the static showMessageDialog() method of the JOptionPane class to create a message dialog. We provide the dialog’s parent, message text, title and a message type. The message type is one of the following constants :
Methods Used :
- setLayout(…) : method help us to set the layout of the container, often a JPanel, to say FlowLayout, BorderLayout, GridLayout, null layout, or whatever layout we want to add on container.
- setBounds(…) : method is used to set the location and size of a components like JButton, and is only useful if null layout is used in JFrame.
- setVisible(…) : method is used to set Visiblity status of JFrame.
- setVisible(true) will set JFrame visible to user.
- setVisible(false) will set JFrame not visible to user.
- getSource() : An event object contains a reference to the component that generated the event. To extract that reference from the event object we use getSource() Method.
- add() : It is used to add components like JButton etc, to the container of JFrame.
- Java.util.BitSet class methods in Java with Examples | Set 2
- Shadowing of static functions in Java
- How does default virtual behavior differ in C++ and Java ?
- How are Java objects stored in memory?
- How are parameters passed in Java?
- Are static local variables allowed in Java?
- final variables in Java
- Default constructor in Java
- Assigning values to static final variables in Java
- Comparison of Exception Handling in C++ and Java
- Does Java support goto?
- Arrays in Java
- Inheritance and constructors in Java
- More restrictive access to a derived class method in Java
- Comparison of static keyword in C++ and Java
Below is the implementation of above discussed method to show Message Dialogs :
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.