Example usage for javax.swing JOptionPane YES_NO_OPTION

List of usage examples for javax.swing JOptionPane YES_NO_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane YES_NO_OPTION.

Prototype

int YES_NO_OPTION

To view the source code for javax.swing JOptionPane YES_NO_OPTION.

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:Main.java

public static void main(String[] args) {
    int result = JOptionPane.showConfirmDialog(null, "This is a test", "Test", JOptionPane.YES_NO_OPTION);

    System.out.println("result: " + result);

    switch (result) {
    case JOptionPane.YES_OPTION:
        System.out.println("Yes Pressed");
        break;/*from  w w  w  . ja  va  2s  .com*/
    case JOptionPane.NO_OPTION:
        System.out.println("No Pressed");
        break;
    case JOptionPane.CLOSED_OPTION:
        System.out.println("Dialog closed");
        break;
    default:
        System.out.println("Default");
        break;
    }
}

From source file:Main.java

public static void main(String args[]) {
    int n = JOptionPane.showOptionDialog(new JFrame(), "Message", "Title", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Yes", "No" }, JOptionPane.YES_OPTION);

    if (n == JOptionPane.YES_OPTION) {
        System.out.println("Yes");
    } else if (n == JOptionPane.NO_OPTION) {
        System.out.println("No");
    } else if (n == JOptionPane.CLOSED_OPTION) {
        System.out.println("Closed by hitting the cross");
    }//www .  ja  v a2  s .co m
}

From source file:MainClass.java

public static void main(String[] a) {
    JOptionPane optionPane = new JOptionPane("Continue printing?", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION);
    JDialog dialog = optionPane.createDialog(null, "Manual Creation");
    dialog.setVisible(true);// ww w.  j av a  2s. c  o  m
}

From source file:OptionDialog.java

public static void main(String argv[]) {
    if (JOptionPane.showConfirmDialog(new JFrame(), "Do you want to quit this application ?", "Title",
            JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
        System.exit(0);/*from   ww w .ja v a2s  . com*/

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame;/*from ww  w. j  a v  a  2 s . c  o  m*/

    Object[] options = { "A", "B", "C", "D" };
    int choice = JOptionPane.showOptionDialog(null, "Nuovo Prodotto", "Scegli il prodotto",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
    if (choice == 0) {
        System.out.println("0 selected");
    } else {
        System.out.println("Something else selected");
    }
}

From source file:CreateDialogFromOptionPane.java

public static void main(final String[] args) {
    JFrame parent = new JFrame();
    JOptionPane optionPane = new JOptionPane("Continue printing?", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION);
    JDialog dialog = optionPane.createDialog(parent, "Manual Creation");
    dialog.setVisible(true);/*from w w w .j a v  a2 s . c om*/
}

From source file:JOptionPaneTest2.java

public static void main(String[] args) {
    JDialog.setDefaultLookAndFeelDecorated(true);
    int response = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (response == JOptionPane.NO_OPTION) {
        System.out.println("No button clicked");
    } else if (response == JOptionPane.YES_OPTION) {
        System.out.println("Yes button clicked");
    } else if (response == JOptionPane.CLOSED_OPTION) {
        System.out.println("JOptionPane closed");
    }/*w  w w .ja v a 2 s.  c om*/
}

From source file:Main.java

public static void main(String[] args) {
    final JFrame frame = new JFrame();
    JOptionPane pane = new JOptionPane("Some message", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION) {
        @Override/*from   w  w w .ja  v a2s  .co m*/
        public void setValue(Object newValue) {
            super.setValue(newValue);
            JOptionPane.showMessageDialog(frame.getContentPane(), "You have hit " + newValue);
        }
    };
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JLabel("Some panel in the middle"), BorderLayout.CENTER);
    frame.add(pane, BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
}

From source file:StringArrayOptionPopups.java

public static void main(String[] a) {
    JFrame frame = new JFrame();

    Icon blueIcon = new ImageIcon("yourFile.gif");
    Object stringArray[] = { "Do It", "No Way" };
    JOptionPane.showOptionDialog(frame, "Continue printing?", "Select an Option", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray, stringArray[0]);
}

From source file:Main.java

public static void main(String[] args) {
    String[] options = { "Button 1", "Button 2", "Button 3" };

    JOptionPane myOptionPane = new JOptionPane("Heres a test message", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION, null, options, options[2]);
    JDialog myDialog = myOptionPane.createDialog(null, "My Test");
    myDialog.setModal(true);/*  w  w w .  j  ava 2 s . c  o m*/

    inactivateOption(myDialog, options[1]);

    myDialog.setVisible(true);
    Object result = myOptionPane.getValue();
    System.out.println("result: " + result);

}