Here you can find the source of confirm(String message, boolean typeYesNo)
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 |
public static boolean confirm(String message, boolean typeYesNo)
//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); } } }