Example usage for javax.swing JOptionPane NO_OPTION

List of usage examples for javax.swing JOptionPane NO_OPTION

Introduction

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

Prototype

int NO_OPTION

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

Click Source Link

Document

Return value from class method if NO 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");
    }// ww w  .ja v  a  2 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.
    }/*from   w  w  w  . j av a  2s .  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;/*  ww w  . j a  v a  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: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. j  a va2 s  .c  o  m
}

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;/*www.  ja  va2 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: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.  j ava 2 s  .  c o m
}

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  w  ww  . java2  s  .com*/
    });

    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 .  j a v a  2 s  .  co m
    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");
    }/*from www .j a  va  2  s  . com*/
}

From source file:net.redstonelamp.gui.RedstoneLampGUI.java

public static void main(String[] args) {
    JFrame frame = new JFrame("RedstoneLamp");
    frame.setLayout(new GridLayout(2, 1));
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    JLabel label = new JLabel("RedstoneLamp");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    frame.add(label);//ww  w.  ja  va2s  . com
    JPanel lowPanel = new JPanel();
    JPanel left = new JPanel();
    left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
    lowPanel.add(left);
    JPanel right = new JPanel();
    right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));
    lowPanel.add(right);
    JButton openButton = new JButton("Open server at...");
    openButton.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(new File("."));
        chooser.setDialogTitle("Select RedstoneLamp server home");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        int action = chooser.showOpenDialog(frame);
        if (action == JFileChooser.APPROVE_OPTION) {
            File selected = chooser.getSelectedFile();
            File jar = new File("RedstoneLamp.jar");
            if (!jar.isFile()) {
                int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. "
                        + "Would you like to install RedstoneLamp there?");
                if (result == JOptionPane.YES_OPTION) {
                    installCallback(frame, selected);
                }
                return;
            }
            frame.dispose();
            addHistory(selected);
            currentRoot = new ServerActivity(selected);
        }
    });
    right.add(openButton);
    JButton installButton = new JButton("Install server at...");
    installButton.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(".");
        chooser.setDialogTitle("Select directory to install server in");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        int action = chooser.showSaveDialog(frame);
        if (action == JFileChooser.APPROVE_OPTION) {
            File selected = chooser.getSelectedFile();
            File jar = new File("RedstoneLamp.jar");
            if (jar.isFile()) {
                int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. "
                        + "Are you sure you want to reinstall RedstoneLamp there?");
                if (result == JOptionPane.NO_OPTION) {
                    frame.dispose();
                    addHistory(selected);
                    currentRoot = new ServerActivity(selected);
                    return;
                }
            }
            installCallback(frame, selected);
        }
    });
    frame.add(lowPanel);
    frame.pack();
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(dimension.width / 2 - frame.getSize().width / 2,
            dimension.height / 2 - frame.getSize().height / 2);
    frame.setVisible(true);
}