VOOZH about

URL: https://www.geeksforgeeks.org/java/message-dialogs-java-gui/

⇱ Message Dialogs in Java (GUI) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Message Dialogs in Java (GUI)

Last Updated : 26 Oct, 2021

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 message type. The message type is one of the following constants : 

  1. ERROR_MESSAGE
  2. WARNING_MESSAGE
  3. QUESTION_MESSAGE
  4. INFORMATION_MESSAGE

Methods Used : 

  1. setLayout(...): method helps 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.
  2. setBounds(...): method is used to set the location and size of components like JButton, and is only useful if null layout is used in JFrame.
  3. setVisible(...): method is used to set the Visibility status of JFrame. 
    1. setVisible(true) will set JFrame visible to user.
    2. setVisible(false) will set JFrame not visible to user.
  4. 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.
  5. add(): It is used to add components like JButton etc, to the container of JFrame.

Below is the implementation of above discussed method to show Message Dialogs :

Output : 

👁 Image

Output : 
 

👁 Image

Output : 

👁 Image

Output : 

👁 Image
Comment
Article Tags:
Article Tags: