Example usage for javax.swing JOptionPane YES_OPTION

List of usage examples for javax.swing JOptionPane YES_OPTION

Introduction

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

Prototype

int YES_OPTION

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

Click Source Link

Document

Return value from class method if YES is chosen.

Usage

From source file:Main.java

public static void main(String args[]) {

    int choose = JOptionPane.showConfirmDialog(null, "Open Dialog  ??");

    if (choose == JOptionPane.YES_OPTION) {
        JOptionPane.showMessageDialog(null, "You Clicked Yes !!");
    } else if (choose == JOptionPane.NO_OPTION) {
        JOptionPane.showMessageDialog(null, "You Clicked NO");
    }/* w w  w  . ja  va 2 s  . 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   w w  w  . ja  v  a2 s  .c  o  m

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    String message = "message";
    int answer = JOptionPane.showConfirmDialog(frame, message);
    if (answer == JOptionPane.YES_OPTION) {
        // User clicked YES.
    } else if (answer == JOptionPane.NO_OPTION) {
        // User clicked NO.
    }// w  w w .j a va2s .  c o m
}

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");
    }/*from w w  w .j  av  a2  s . c o  m*/
}

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 .jav  a 2s .c o  m*/
    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 response = JOptionPane.showConfirmDialog(null, "Save the file?", "Confirm  Save  Changes",
            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);

    switch (response) {
    case JOptionPane.YES_OPTION:
        System.out.println("yes");
        break;//from   ww w. j  a v a  2  s  .c  o  m
    case JOptionPane.NO_OPTION:
        System.out.println("no");
        break;
    case JOptionPane.CANCEL_OPTION:
        System.out.println("cancel");
        break;
    case JOptionPane.CLOSED_OPTION:
        System.out.println("closed.");
        break;
    default:
        System.out.println("something else");
    }

}

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");
    }/*  ww w. j av  a2  s .  c om*/
}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();

    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            int result = JOptionPane.showConfirmDialog(frame, "Do you want to Exit ?", "Exit Confirmation : ",
                    JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.YES_OPTION)
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            else if (result == JOptionPane.NO_OPTION)
                frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        }/*from   ww  w  .  jav  a 2s.  c o  m*/
    });

    frame.setSize(300, 300);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(200, 200);/*from  w ww. ja va 2s  .com*/
    frame.setVisible(true);

    JOptionPane.showMessageDialog(frame, "A");
    JOptionPane.showMessageDialog(frame, "B", "message", JOptionPane.WARNING_MESSAGE);

    int result = JOptionPane.showConfirmDialog(null, "Remove now?");
    switch (result) {
    case JOptionPane.YES_OPTION:
        System.out.println("Yes");
        break;
    case JOptionPane.NO_OPTION:
        System.out.println("No");
        break;
    case JOptionPane.CANCEL_OPTION:
        System.out.println("Cancel");
        break;
    case JOptionPane.CLOSED_OPTION:
        System.out.println("Closed");
        break;
    }

    String name = JOptionPane.showInputDialog(null, "Please enter your name.");
    System.out.println(name);

    JTextField userField = new JTextField();
    JPasswordField passField = new JPasswordField();
    String message = "Please enter your user name and password.";
    result = JOptionPane.showOptionDialog(frame, new Object[] { message, userField, passField }, "Login",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    if (result == JOptionPane.OK_OPTION)
        System.out.println(userField.getText() + " " + new String(passField.getPassword()));

}

From source file:MainClass.java

public static void main(final String args[]) {
    UIManager.put("OptionPane.cancelButtonText", "Annuler");
    UIManager.put("OptionPane.noButtonText", "Non");
    UIManager.put("OptionPane.okButtonText", "D'accord");
    UIManager.put("OptionPane.yesButtonText", "Oui");

    int result = JOptionPane.showConfirmDialog(new JFrame(), "Est-ce que vous avez 18 ans ou plus?",
            "Choisisez une option", JOptionPane.YES_NO_CANCEL_OPTION);
    if (result == JOptionPane.YES_OPTION) {
        System.out.println("Yes");
    } else if (result == JOptionPane.NO_OPTION) {
        System.out.println("No");
    } else if (result == JOptionPane.CANCEL_OPTION) {
        System.out.println("Cancel");
    } else if (result == JOptionPane.CLOSED_OPTION) {
        System.out.println("Closed");
    }//w  w  w  .  j a va  2s .co m
}