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 WindowAdapter createConfirmOnExitAdapter(final JFrame frame, final String title,
        final String message) {
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    return new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent ev) {
            int result = JOptionPane.showConfirmDialog(frame, message, title, JOptionPane.YES_OPTION);
            if (result == JOptionPane.OK_OPTION) {
                frame.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                System.exit(0);//from  ww  w  .  ja v a2  s  . c o  m
            }
        }
    };
}

From source file:Main.java

/**
 * Displays a confirmation window asking a user a yes or no question.
 * @param message   the message to show.
 * @param parent   Parent component of this dialog.
 * @return         true if "yes" was clicked. false otherwise.
 *//*from w  w w  .  j a va2 s.  co  m*/
public static boolean yesTo(String message, Component parent) {
    int c = JOptionPane.showConfirmDialog(parent, message, "Confirm", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    boolean out = c == JOptionPane.YES_OPTION;
    return out;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
        }/* www.  ja  va2s . c  o m*/

        public void windowClosing(WindowEvent e) {
            if (JOptionPane.showConfirmDialog(null, "Are you sure ?") == JOptionPane.YES_OPTION) {
                setVisible(false);
                dispose();
            }
        }
    });
    pack();
    setVisible(true);
}

From source file:Dialogs.java

public static boolean showYesNo(Component owner, String msg, String title) {
    int rc = JOptionPane.showConfirmDialog(owner, msg, title, JOptionPane.YES_NO_OPTION);
    return rc == JOptionPane.YES_OPTION;
}

From source file:Main.java

public Main() {
    setSize(200, 200);/*from   w  ww. j  ava2 s  .  c  o m*/
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            Object[] options = { "Quit, My Computing Fellow", "No, I want to Work more" };

            int answer = JOptionPane.showOptionDialog(Main.this, "What would you like to do? ", "Quit:Continue",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            if (answer == JOptionPane.YES_OPTION) {
                System.exit(0);
            }
        }
    });
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(new JLabel("Placeholder label"));
    pack();/*from w  w  w . j a  v  a2 s  .com*/
    setSize(200, 200);
    setVisible(true);

    int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?");

    String result = "?";
    switch (replaced) {
    case JOptionPane.CANCEL_OPTION:
        result = "Canceled";
        break;
    case JOptionPane.CLOSED_OPTION:
        result = "Closed";
        break;
    case JOptionPane.NO_OPTION:
        result = "No";
        break;
    case JOptionPane.YES_OPTION:
        result = "Yes";
        break;
    default:
        ;
    }
    System.out.println("Replace? " + result);
}

From source file:Test.java

public Test() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(new JLabel("Placeholder label"));
    pack();/*from  ww  w .j  a v  a2  s . com*/
    setSize(200, 200);
    setVisible(true);

    int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?");

    String result = "?";
    switch (replaced) {
    case JOptionPane.CANCEL_OPTION:
        result = "Canceled";
        break;
    case JOptionPane.CLOSED_OPTION:
        result = "Closed";
        break;
    case JOptionPane.NO_OPTION:
        result = "No";
        break;
    case JOptionPane.YES_OPTION:
        result = "Yes";
        break;
    default:
        ;
    }
    System.out.println("Replace? " + result);
}

From source file:Main.java

/**Prompt the user to choose between two courses of action.
 @return true if the user chose the default course of action,
   false if the alternate course was chosen of the prompt closed.*/
public static boolean prompt2(Component parent, String question, String title, String defaultActionText,
        String alternateActionText) {
    Object[] values = new Object[] { defaultActionText, alternateActionText };

    int choice = JOptionPane.showOptionDialog(parent, question, title, JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, values, values[0]);

    return choice == JOptionPane.YES_OPTION;
}

From source file:Main.java

/**
 * Asks the user for confirmation.//w  w w  . j  a  v a2s.  c  om
 * 
 * @param aWindow
 *          the parent window of the confirmation dialog;
 * @param aMessage
 *          the message to display in the confirmation dialog;
 * @param aTitle
 *          the title to display in the confirmation dialog.
 * @return <code>true</code> if the user acknowledged the confirmation,
 *         <code>false</code> otherwise.
 */
public static boolean askConfirmation(final Window aWindow, final String aMessage, final String aTitle) {
    return JOptionPane.showConfirmDialog(aWindow, aMessage, aTitle, JOptionPane.YES_NO_OPTION,
            JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION;
}

From source file:br.com.pontocontrol.controleponto.ControlePonto.java

public static void solicitarLogin() {
    String usuario;//from  w  ww . jav  a  2  s  . c  o m
    do {
        usuario = JOptionPane.showInputDialog(null, "Informe seu usurio:", "Identificao",
                JOptionPane.INFORMATION_MESSAGE);
        if (StringUtils.isBlank(usuario)) {
            JOptionPane.showMessageDialog(null, "Informe um login de usurio.", "Validao falhou.",
                    JOptionPane.ERROR_MESSAGE);
        }
    } while (StringUtils.isBlank(usuario));
    switch (SessaoManager.getInstance().autenticar(usuario)) {
    case SessaoManager.LOGIN_STATUS.OK:

        break;
    case SessaoManager.LOGIN_STATUS.USUARIO_NAO_EXISTE:
        int opt = JOptionPane.showConfirmDialog(null,
                format("O usurio com o login informado \"%s\" no existe, deseja criar um novo usurio?",
                        usuario),
                "Usurio no encontrado.", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        if (JOptionPane.YES_OPTION == opt) {
            ConfiguracoesUsuario configuracoesUsuario = new ConfiguracoesUsuario(usuario);
            SessaoManager.getInstance().criarUsuario(configuracoesUsuario);
            SessaoManager.getInstance().autenticar(usuario);
        }
        break;
    default:

        break;
    }
}