Example usage for javax.swing JOptionPane showOptionDialog

List of usage examples for javax.swing JOptionPane showOptionDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane showOptionDialog.

Prototype

@SuppressWarnings("deprecation")
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType,
        int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException 

Source Link

Document

Brings up a dialog with a specified icon, where the initial choice is determined by the initialValue parameter and the number of choices is determined by the optionType parameter.

Usage

From source file:zxmax.tools.timerreview.gui.StartTimerWindow.java

private void storeDataAndStartTimer() {

    // prepare data to store
    Tomato tomato = new Tomato(taFocusOn.getText());
    tomato.setTitle(tfTitle.getText());//from w w  w.j  ava  2  s . c o m

    try {
        tomato.setDuration(Integer.parseInt(txtDurata.getText()));
    } catch (NumberFormatException ex) {
        tomato.setDuration(1);
    }

    List<String> errorMessages = validatorService.validate(tomato);
    int response = 0;
    if (errorMessages.size() > 0) {
        String message = StringUtils.join(errorMessages, System.getProperty("line.separator"));
        response = JOptionPane.showOptionDialog(null, message,
                I18N.getLabel(this.getClass(), "error.box.title"), JOptionPane.DEFAULT_OPTION,
                JOptionPane.PLAIN_MESSAGE, null, new Object[] {}, null);
    }

    if (response > -1) {

        getBasicDao().save(tomato);
        logger.debug(tomato.toString());

        StringBuilder sb = new StringBuilder();
        // sb.append((new LocalDateTime()).toString("dd/MM/yyyy HH:mm"))
        // .append(System.getProperty("line.separator"));

        sb.append(OrgModeDecorator.ORG_MODE_LEVEL_1 + I18N.getLabel(this.getClass(), TIMER_LOGGER_TITOLO))

                .append(tomato.getTitle()).append(System.getProperty("line.separator"));
        sb.append(OrgModeDecorator.ORG_MODE_LEVEL_2 + I18N.getLabel(this.getClass(), TIMER_LOGGER_FOCUS_ON))
                .append(tomato.getFocusOn());

        reportLogger.info(sb.toString());

        disableNewTimerMenuItem();

        startCountdown(tomato);

        UINotificationService uiNotificationService = new UINotificationService(tomato);
        Register.put(UINotificationService.class, uiNotificationService);

        closeThisWindow();
    }
}

From source file:zxmax.tools.timerreview.Main.java

public static void main(final String[] args) {
    try {/*  w  w w . j  a v a2s  . com*/

        JustOneLock ua = new JustOneLock(".timerreview");
        if (ua.isAppActive()) {
            String message = I18N.getLabel(MyUncaughtExceptionHandler.class, "another.instance.already.open");

            JOptionPane.showOptionDialog(null, message,
                    I18N.getLabel(MyUncaughtExceptionHandler.class, "error.box.title"),
                    JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[] {}, null);

            System.exit(0);
        }
        new Main();
    } catch (Exception e) {

        if (e instanceof IllegalStateException) {
            JOptionPane.showMessageDialog(null,
                    "controlla i file di log e contatta, se ti va, lo sviluppatore, ciao.");
        }
        LOGGER.error("", e);
    }
}