JOptionPane




The JOptionPane class allows you to display a message dialog box or an input box. These are static methods, so you don't need to create any objects, just use the class name . method name.
You must import javax.swing.JOptionPane;

Examples:


// the showInputDialog method shows an Ok and Cancel button
// if the user clicks on Ok, you get back a String
// if the user clicks on Cancel, you get back null
String result;
result = JOptionPane.showInputDialog(this, "Enter the person's name");


// the showMessageDialog shows your message and an Ok button
JOptionPane.showMessageDialog(null, "The name entered was "+result);