Java JOptionPane Confirmation confirm(String message, boolean typeYesNo)

Here you can find the source of confirm(String message, boolean typeYesNo)

Description

Pops up a confirmation dialog that requires user to type the word Yes into a text field in order to confirm the question asked.

License

Open Source License

Parameter

Parameter Description
message The message to be asked of the user. Should be worded for a yes/no answer.
typeYesNo When true, will force the user to actually type "Yes" intead of simply hitting a Yes button

Declaration

public static boolean confirm(String message, boolean typeYesNo) 

Method Source Code

//package com.java2s;
// This software is licensed under the GNU General Public License,

import java.util.ResourceBundle;

public class Main {
    public static final String NEWLINE = System.getProperty("line.separator");
    static ResourceBundle resUtil = null;

    /**// w  w w  .jav  a  2  s . c o m
     * Pops up a confirmation dialog that requires user to type the word Yes into a text field in order to confirm the
     * question asked.
     * 
     * @param message
     *           The message to be asked of the user. Should be worded for a yes/no answer.
     * @returns true if user replied 'yes' or false if they gave any other answer
     */
    public static boolean confirm(String message) {
        return confirm(message, true);
    }

    /**
     * Pops up a confirmation dialog that requires user to type the word Yes into a text field in order to confirm the
     * question asked.
     * 
     * @param message
     *           The message to be asked of the user. Should be worded for a yes/no answer.
     * @param typeYesNo
     *           When true, will force the user to actually type "Yes" intead of simply hitting a Yes button
     * @returns true if user replied 'yes' or false if they gave any other answer
     */
    public static boolean confirm(String message, boolean typeYesNo) {
        if (typeYesNo) {
            StringBuffer fullMsg = new StringBuffer(message);
            fullMsg.append(NEWLINE);
            fullMsg.append(NEWLINE);
            fullMsg.append(resUtil.getString("YesNoMessage"));
            String answer = javax.swing.JOptionPane.showInputDialog(null, fullMsg.toString(),
                    resUtil.getString("YesNoTitle"), javax.swing.JOptionPane.QUESTION_MESSAGE);
            return (answer != null && answer.equalsIgnoreCase(resUtil.getString("Yes")));
        } else {
            int answer = javax.swing.JOptionPane.showConfirmDialog(null, message, resUtil.getString("YesNoTitle"),
                    javax.swing.JOptionPane.YES_NO_OPTION);
            return (answer == javax.swing.JOptionPane.YES_OPTION);
        }
    }
}

Related

  1. askConfirmation(final Window aWindow, final String aMessage, final String aTitle)
  2. confirm(Component component, String title, String msg)
  3. confirm(final Component component, final String title, final String message)
  4. confirm(String message)
  5. confirm(String message)
  6. confirm(String message, String title)
  7. confirm(String msg)
  8. confirm(String title, Object message, JComponent parent)
  9. confirmAction(Component comp, String title, String msg)