Create a ok cancel dialog with JOptionPane in Java

Description

The following code shows how to create a ok cancel dialog with JOptionPane.

Example


import java.awt.Component;
/*from  w w  w. jav  a  2 s.  c om*/
import javax.swing.JOptionPane;

public class Main {
  public static void main(String[] argv) throws Exception {
    int i = okcancel("Are your sure ?");
    System.out.println("ret : " + i);

  }

  public static int okcancel(String theMessage) {
    int result = JOptionPane.showConfirmDialog((Component) null, theMessage,
        "alert", JOptionPane.OK_CANCEL_OPTION);
    return result;
  }

}

The code above generates the following result.

Create a ok cancel dialog with JOptionPane in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer