NotifyDescriptor经典用法

private static boolean showDialog(URL whereTo) {
        String msg = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Message");
        String tit = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Title");
        String yes = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Yes");
        String later = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Later");
        String never = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Never");
        
        NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.QUESTION_MESSAGE);
        nd.setTitle(tit);
        //Object[] buttons = { yes, later, never };
        JButton yesButton = new JButton();
        yesButton.getAccessibleContext().setAccessibleDescription( 
                NbBundle.getMessage(FeedbackSurvey.class, "ACSD_FeedbackSurvey_Yes"));
        Mnemonics.setLocalizedText(yesButton, yes);
        JButton laterButton = new JButton();
        laterButton.getAccessibleContext().setAccessibleDescription( 
                NbBundle.getMessage(FeedbackSurvey.class, "ACSD_FeedbackSurvey_Later"));
        Mnemonics.setLocalizedText(laterButton, later);
        JButton neverButton = new JButton();
        neverButton.getAccessibleContext().setAccessibleDescription( 
                NbBundle.getMessage(FeedbackSurvey.class, "ACSD_FeedbackSurvey_Never"));
        Mnemonics.setLocalizedText(neverButton, never);
        Object[] buttons = { yesButton, laterButton, neverButton };
        nd.setOptions(buttons);
        Object res = DialogDisplayer.getDefault().notify(nd);
        
        if (res == yesButton) {
            HtmlBrowser.URLDisplayer.getDefault().showURL(whereTo);
            return true;
        } else {
            if( res == neverButton ) {
                Preferences prefs = NbPreferences.forModule(FeedbackSurvey.class);
                prefs.putInt("feedback.survey.show.count", (int)bundledInt("MSG_FeedbackSurvey_AskTimes")); // NOI18N
            }
            return false;
        }
    }

你可能感兴趣的:(script)