當前位置: 首頁>>代碼示例>>Java>>正文


Java JOptionPane.YES_NO_CANCEL_OPTION屬性代碼示例

本文整理匯總了Java中javax.swing.JOptionPane.YES_NO_CANCEL_OPTION屬性的典型用法代碼示例。如果您正苦於以下問題:Java JOptionPane.YES_NO_CANCEL_OPTION屬性的具體用法?Java JOptionPane.YES_NO_CANCEL_OPTION怎麽用?Java JOptionPane.YES_NO_CANCEL_OPTION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.swing.JOptionPane的用法示例。


在下文中一共展示了JOptionPane.YES_NO_CANCEL_OPTION屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: confirm

/**
 * Indicates if this option is confirmed. This can be either because its
 * value is {@link #ALWAYS}, or because the user has confirmed an
 * appropriate dialog.
 * @param owner the component on which the dialog is to be shown
 * @param question if not <code>null</code>, replaces the name of the
 *        option in the dialog
 * @return <code>true</code> if the option is confirmed.
 */
public boolean confirm(Component owner, String question) {
    if (this.value == ASK) {
        if (question == null) {
            question = getText();
        }
        List<String> options = getDialogOptions();
        JOptionPane pane =
            new JOptionPane(question, JOptionPane.QUESTION_MESSAGE,
                JOptionPane.YES_NO_CANCEL_OPTION, null, options.toArray());
        pane.createDialog(owner, DIALOG_TITLE).setVisible(true);
        int dialogValue = options.indexOf(pane.getValue());
        if (dialogValue > NO) {
            setValue(dialogValue - 1);
        }
        return dialogValue == YES || dialogValue - 1 == ALWAYS;
    } else {
        return this.value == ALWAYS;
    }
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:28,代碼來源:BehaviourOption.java

示例2: setCallback

void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:66,代碼來源:DialogCallbackHandler.java


注:本文中的javax.swing.JOptionPane.YES_NO_CANCEL_OPTION屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。