Java JOptionPane Message showYesNo(Component parent, String title, String message)

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

Description

show Yes No

License

Open Source License

Declaration

public static boolean showYesNo(Component parent, String title, String message) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w.jav a  2  s  . co  m*/
  Copyright (c) 2005-2014 www.kodemore.com
    
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
    
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
    
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/

import java.awt.Component;

import javax.swing.JDialog;

import javax.swing.JOptionPane;

public class Main {
    public static boolean showYesNo(Component parent, String title, String message) {
        int IGNORED = -1;

        Object no = "No";
        Object yes = "Yes";

        Object arr[];
        arr = new Object[2];
        arr[0] = no;
        arr[1] = yes;

        JOptionPane p;
        p = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, IGNORED);
        p.setOptions(arr);
        p.setInitialValue(no);

        int i = _show(p, parent, title);

        if (i == 0)
            return false;

        if (i == 1)
            return true;

        return false;
    }

    public static int _show(JOptionPane p, Component parent, String title) {
        JDialog d;
        d = p.createDialog(parent, title);
        d.setVisible(true);

        Object selectedValue = p.getValue();
        if (selectedValue == null)
            return JOptionPane.CLOSED_OPTION;

        Object options[] = p.getOptions();
        if (options == null) {
            if (selectedValue instanceof Integer)
                return (Integer) selectedValue;
            return JOptionPane.CLOSED_OPTION;
        }

        int n = options.length;
        for (int i = 0; i < n; i++)
            if (options[i].equals(selectedValue))
                return i;

        return JOptionPane.CLOSED_OPTION;
    }
}

Related

  1. ShowOkCancelMessage(String msg)
  2. ShowOkMessage(String msg)
  3. showPrettyYesNoPane(Component caller, String msg, String title)
  4. showQuestionThreeChoicesBox(Component pParent, String pMessage, String pTitle, String pLeftOption, String pMiddleOption, String pRightOption)
  5. showSuccessMessage(Component parentComponent, String message)
  6. showYesNoCancel_old(Component parent, String title, String message)
  7. showYesNoMessage(Component parent, String message)
  8. testInput(String message)
  9. yesNo(Component parent, String message, String title)