ADS

3 Ways To Show Joptionpane Message Dialog

 The following dead simple jadwal illustrates  3 Ways to Show JOptionPane Message Dialog
The following dead simple jadwal illustrates 3 ways to show message obrolan in JOptionPane.

import javax.swing.*;
import java.awt.*;
class MessageDialogExample extends JFrame
{

    public MessageDialogExample()
    {
        createAndShowGUI();
    }
   
    private void createAndShowGUI()
    {
        setTitle("JSplitPane Example");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
       
        // These display one after the other is closed
        JOptionPane.showMessageDialog(this,"This is message - 1");
        JOptionPane.showMessageDialog(this,"This is message - 2","This is title",JOptionPane.WARNING_MESSAGE);
        JOptionPane.showMessageDialog(this,"This is message - 3","This is title",JOptionPane.WARNING_MESSAGE,new ImageIcon("imageicon.png"));
       
       
        setSize(400,400);
        setVisible(true);   
    }
   
    public static void main(String args[])
    {
    SwingUtilities.invokeLater(new Runnable(){
            public void run()
            {
            new MessageDialogExample();
            }
        });
    }
}

showMessageDialog(): The three overloaded versions of these methods take in the parent component represented as this followed by the message to be displayed in the JOptionPane, it's title, type of message (warning or error or information etc) and image icon to be displayed.

Subscribe to receive free email updates:

ADS