Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

JOptionPane.showMessageDialog

 

 

 

Parameters

The parameter list consists of 4 components:

 

   The first argument is the component over which the dialog is to appear.

 
      You typically specify the main window or panel of your application. If you specify null, then the dialog will simply be centered on the screen. (USE THIS OPTION)

 

   The second argument is the message to be displayed

 

   The third argument displays the text to appear in the titlebar of the dialog

 

   The fourth argument is the message type - as shown below

 

  Dialog Type

  Icon

  Description

JOptionPane.ERROR_MESSAGE

A Dash

Indicates an error to the user

JOptionPane.INFORMATION_MESSAGE

An i

Display an informational message

JOptionPane.WARNING_MESSAGE

Exclamation Mark

Warns user of a potential problem

JOptionPane.QUESTION_MESSAGE

Question Mark

Poses a question to the user

JOptionPane.PLAIN_MESSAGE

No Icon

Contains a message with no icon

 

Example 1

 

import javax.swing.*;
 
class MDConstants
{
  public static void main (String []args)
  {
    JOptionPane.showMessageDialog(null, "The Message", "The Title", JOptionPane.QUESTION_MESSAGE);
  }
}

 

 

 

 

 

 

 

Example 2

 

import javax.swing.*;

 

class TextArea

{

  public static void main (String []args)

      {

         String output = "Rating\tFrequency\n";

         for (int i = 0; i < 10; i++)

              output = output + i + "\t" + i+1 + "\n";

         JTextArea outputArea = new JTextArea();

         outputArea.setText(output);

         JOptionPane.showMessageDialog (null, outputArea, "Example", JOptionPane.INFORMATION_MESSAGE);

       }

}