Java JOptionPane Confirmation quitConfirmed(Component parent, String message)

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

Description

Quit Confirmation pop up dialog

License

Open Source License

Parameter

Parameter Description
parent - parent component
message - message to use instead of default

Return

boolean if quit (true) or cancel dialog (false)

Declaration

public static boolean quitConfirmed(Component parent, String message) 

Method Source Code

//package com.java2s;
/*//from w w  w. ja  v a 2s. c  om
 * ome.formats.importer.gui.GuiCommonElements
 *
 *------------------------------------------------------------------------------
 *  Copyright (C) 2006-2008 University of Dundee. All rights reserved.
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *------------------------------------------------------------------------------
 */

import java.awt.Component;

import javax.swing.JOptionPane;

public class Main {
    /**
     * Quit Confirmation pop up dialog
     * 
     * @param parent - parent component
     * @param message - message to use instead of default
     * @return boolean if quit (true) or cancel dialog (false)
     */
    public static boolean quitConfirmed(Component parent, String message) {
        if (message == null) {
            message = "Do you really want to close the application?\n"
                    + "Doing so will cancel any running imports.";
        }
        String s1 = "No";
        String s2 = "Yes";
        Object[] options = { s2, s1 };
        int n = JOptionPane.showOptionDialog(parent, message, "Exit Application", JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, options, s1);
        //b/c of switch of location
        if (n == JOptionPane.YES_OPTION) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. getConfirmation(Component parent, String str)
  2. getUserConfirmation(Component cp, String message)
  3. getUserConfirmation(String arg1)
  4. listConfirm(Component comp, String title, String message, Object[] listModel)
  5. pedeConfirmacao(String msg, int opcoes, int tipoMsg)
  6. retrieveUserConfirmation(String title, String message)
  7. showConfirm(final Component rootComponent, final String message, final String title)
  8. showConfirm(String message)
  9. showConfirmation(Component component, String message)