Java JOptionPane Message yesTo(String message, Component parent)

Here you can find the source of yesTo(String message, Component parent)

Description

Displays a confirmation window asking a user a yes or no question.

License

Open Source License

Parameter

Parameter Description
message the message to show.
parent Parent component of this dialog.

Return

true if "yes" was clicked. false otherwise.

Declaration

public static boolean yesTo(String message, Component parent) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009-2014 Black Rook Software
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 ******************************************************************************/

import java.awt.Component;

import javax.swing.JOptionPane;

public class Main {
    /**//w  w  w  .  j  a  va 2 s .c o  m
     * Displays a confirmation window asking a user a yes or no question.
     * @param message   the message to show.
     * @return         true if "yes" was clicked. false otherwise.
     */
    public static boolean yesTo(String message) {
        return yesTo(message, null);
    }

    /**
     * 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.
     */
    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;
    }
}

Related

  1. showYesNo(Component parent, String title, String message)
  2. showYesNoCancel_old(Component parent, String title, String message)
  3. showYesNoMessage(Component parent, String message)
  4. testInput(String message)
  5. yesNo(Component parent, String message, String title)