Example usage for javax.swing JOptionPane YES_OPTION

List of usage examples for javax.swing JOptionPane YES_OPTION

Introduction

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

Prototype

int YES_OPTION

To view the source code for javax.swing JOptionPane YES_OPTION.

Click Source Link

Document

Return value from class method if YES is chosen.

Usage

From source file:emailplugin.MailCreator.java

/**
 * Shows a Warning if the Plugin was not configured correctly.
 *
 * @param parent Parent-Dialog// w  w w .j  a va 2  s .  c o m
 */
private void showNotConfiguredCorrectly(Frame parent) {
    int ret = JOptionPane.showConfirmDialog(parent,
            mLocalizer.msg("NotConfiguredCorrectly", "Not configured correctly"),
            Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.YES_NO_OPTION,
            JOptionPane.ERROR_MESSAGE);

    if (ret == JOptionPane.YES_OPTION) {
        Plugin.getPluginManager().showSettings(mPlugin);
    }
}

From source file:biz.wolschon.finance.jgnucash.panels.TaxReportPanel.java

/**
 * Show a dialog to export/*from ww w  .  j a v a2  s . c  om*/
 * a CSV-file that contains the
 * shown {@link TransactionSum}s
 * for each month, year or day.
 */
protected void showExportCSVDialog() {
    JFileChooser fc = new JFileChooser();
    fc.setAcceptAllFileFilterUsed(true);
    fc.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(final File aF) {
            return aF.isDirectory() || aF.getName().endsWith(".csv");
        }

        @Override
        public String getDescription() {
            return "CSV-file";
        }
    });
    int dialogResult = fc.showSaveDialog(this);
    if (dialogResult != JFileChooser.APPROVE_OPTION) {
        return;
    }
    File file = fc.getSelectedFile();
    if (file.exists()) {
        int confirmation = JOptionPane.showConfirmDialog(this, "File exists. Replace file?");
        if (confirmation != JOptionPane.YES_OPTION) {
            showExportCSVDialog();
            return;
        }
    }
    ExportGranularities gran = (ExportGranularities) myExportGranularityCombobox.getSelectedItem();
    try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        exportCSV(file, gran);
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }
}

From source file:gdt.jgui.entity.JEntitiesPanel.java

/**
 * Get context menu.//from   w  ww .  j av  a2  s  .co  m
 * @return the context menu.
 * 
 */
@Override
public JMenu getContextMenu() {
    menu = super.getContextMenu();
    mia = null;
    int cnt = menu.getItemCount();
    if (cnt > 0) {
        mia = new JMenuItem[cnt];
        for (int i = 0; i < cnt; i++)
            mia[i] = menu.getItem(i);
    }
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            menu.removeAll();
            if (mia != null)
                for (JMenuItem mi : mia)
                    try {
                        if (mi != null)
                            menu.add(mi);
                    } catch (Exception ee) {
                        System.out.println("JEntitiesPanel:getConextMenu:" + ee.toString());
                    }
            Properties locator = Locator.toProperties(locator$);
            if (locator.getProperty(EntityHandler.ENTITY_CONTAINER) != null) {
                if (JEntityPrimaryMenu.hasToPaste(console, locator$)) {
                    pasteItem = new JMenuItem("Paste components");
                    pasteItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            pasteComponents();
                        }
                    });
                    menu.add(pasteItem);
                }
                if (hasSelectedItems()) {
                    if (containerKey$ != null) {
                        removeComponentsItem = new JMenuItem("Remove components");
                        removeComponentsItem.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                removeComponents();
                            }
                        });
                        menu.add(removeComponentsItem);
                    }
                }
            }
            if (locator.getProperty(EntityHandler.ENTITY_COMPONENT) != null) {
                if (componentKey$ != null) {
                    removeContainersItem = new JMenuItem("Remove containers");
                    removeContainersItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            removeContainers();
                        }
                    });
                    menu.add(removeContainersItem);
                }
            }
            if (hasSelectedItems()) {
                menu.addSeparator();
                copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JItemPanel[] ipa = JEntitiesPanel.this.getItems();
                        ArrayList<String> sl = new ArrayList<String>();
                        for (JItemPanel ip : ipa)
                            if (ip.isChecked())
                                sl.add(ip.getLocator());
                        String[] sa = sl.toArray(new String[0]);
                        console.clipboard.clear();
                        for (String aSa : sa)
                            console.clipboard.putString(aSa);
                    }
                });
                menu.add(copyItem);
                reindexItem = new JMenuItem("Reindex");
                reindexItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JItemPanel[] ipa = JEntitiesPanel.this.getItems();
                        for (JItemPanel ip : ipa)
                            if (ip.isChecked()) {
                                JEntityPrimaryMenu.reindexEntity(console, ip.getLocator());
                            }
                    }
                });
                menu.add(reindexItem);
                archiveItem = new JMenuItem("Archive");
                archiveItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JItemPanel[] ipa = JEntitiesPanel.this.getItems();
                        Entigrator entigrator = console.getEntigrator(entihome$);
                        Properties locator;
                        ArrayList<String> sl = new ArrayList<String>();
                        String entityKey$;
                        for (JItemPanel ip : ipa) {
                            if (ip.isChecked()) {
                                locator = Locator.toProperties(ip.getLocator());
                                entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
                                sl.add(entityKey$);
                            }
                        }
                        String[] sa = sl.toArray(new String[0]);
                        System.out.println("JEntitiesPanel:archive:1");
                        String[] ea = JReferenceEntry.getCoalition(console, entigrator, sa);
                        if (ea == null)
                            System.out.println("JEntitiesPanel:archive:ea null");
                        else
                            System.out.println("JEntitiesPanel:archive:ea=" + ea.length);
                        JArchivePanel archivePanel = new JArchivePanel();
                        String apLocator$ = archivePanel.getLocator();
                        //locator$=getLocator();
                        apLocator$ = Locator.append(apLocator$, Entigrator.ENTIHOME, entihome$);
                        apLocator$ = Locator.append(apLocator$, EntityHandler.ENTITY_LIST,
                                Locator.toString(ea));
                        String icon$ = Support.readHandlerIcon(null, JEntityPrimaryMenu.class, "archive.png");
                        apLocator$ = Locator.append(apLocator$, Locator.LOCATOR_ICON, icon$);
                        JConsoleHandler.execute(console, apLocator$);
                    }
                });
                menu.add(archiveItem);
                menu.addSeparator();
                deleteItem = new JMenuItem("Delete");
                deleteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?",
                                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {
                            JItemPanel[] ipa = JEntitiesPanel.this.getItems();
                            Entigrator entigrator = console.getEntigrator(entihome$);
                            String iLocator$;
                            Properties iLocator;
                            String iEntityKey$;
                            String iEntityLabel$;
                            Sack iEntity;
                            ArrayList<String> sl = new ArrayList<String>();
                            for (JItemPanel ip : ipa) {
                                iLocator$ = ip.getLocator();
                                iLocator = Locator.toProperties(iLocator$);
                                iEntityLabel$ = iLocator.getProperty(EntityHandler.ENTITY_LABEL);
                                if (ip.isChecked()) {
                                    iEntityKey$ = iLocator.getProperty(EntityHandler.ENTITY_KEY);
                                    iEntity = entigrator.getEntityAtKey(iEntityKey$);
                                    if (iEntity != null)
                                        entigrator.deleteEntity(iEntity);
                                } else {
                                    sl.add(iEntityLabel$);
                                }
                            }
                            String[] sa = sl.toArray(new String[0]);
                            if (sa != null && sa.length > 0) {
                                String sa$ = Locator.toString(sa);
                                locator$ = Locator.append(locator$, EntityHandler.ENTITY_LIST, sa$);
                            }
                            JConsoleHandler.execute(console, locator$);
                        }
                    }
                });
                menu.add(deleteItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    menu.addSeparator();
    JMenuItem doneItem = new JMenuItem("Done");
    doneItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (requesterResponseLocator$ != null) {
                try {
                    byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                    String responseLocator$ = new String(ba, "UTF-8");
                    JConsoleHandler.execute(console, responseLocator$);
                } catch (Exception ee) {
                    LOGGER.severe(ee.toString());
                }
            } else
                console.back();
        }
    });
    menu.add(doneItem);
    return menu;
}

From source file:com.floreantpos.bo.ui.explorer.QuickMaintenanceExplorer.java

private static void quickMaintainOrderType(OrderType orderType) {
    try {// w  w w  .j  a  v a 2s .c om
        if (orderType.getId() != null) {
            if (btnCopy.isSelected()) {
                OrderType newOrderType = new OrderType();
                PropertyUtils.copyProperties(newOrderType, orderType);
                newOrderType.setId(null);
                orderType = newOrderType;
            } else if (btnDelete.isSelected()) {
                if (POSMessageDialog.showYesNoQuestionDialog(POSUtil.getFocusedWindow(),
                        POSConstants.CONFIRM_DELETE, POSConstants.DELETE) != JOptionPane.YES_OPTION) {
                    return;
                }

                OrderTypeDAO orderTypeDAO = new OrderTypeDAO();
                orderTypeDAO.delete(orderType.getId());
                SwitchboardView.getInstance().rendererOrderPanel();
                return;
            }
        }
        OrderTypeForm editor = new OrderTypeForm(orderType);
        BeanEditorDialog dialog = new BeanEditorDialog(Application.getPosWindow(), editor);
        dialog.open();
        if (dialog.isCanceled())
            return;
        Application.getInstance().refreshOrderTypes();
        SwitchboardView.getInstance().rendererOrderPanel();
        return;
    } catch (Exception e) {
        return;
    }
}

From source file:at.becast.youploader.gui.FrmMain.java

/**
 * Creates new form frmMain/*w  ww  .  jav  a 2s.  com*/
 */
public FrmMain() {
    self = this;
    this.tos = false;
    this.setMinimumSize(new Dimension(900, 580));
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            LOG.info(Main.APP_NAME + " " + Main.VERSION + " closing.", FrmMain.class);
            Main.s.put("left", String.valueOf(getX()));
            Main.s.put("top", String.valueOf(getY()));
            Main.s.put("width", String.valueOf(getWidth()));
            Main.s.put("height", String.valueOf(getHeight()));
            LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
            loggerContext.stop();
            e.getWindow().dispose();
        }
    });
    UploadMgr = UploadManager.getInstance();
    TemplateMgr = TemplateManager.getInstance();
    UploadMgr.setParent(this);
    String sspeed = Main.s.setting.get("speed");
    if (sspeed != null) {
        speed = Integer.parseInt(sspeed);
    } else {
        speed = 0;
    }
    initComponents();
    initMenuBar();
    loadAccounts();
    this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/yp.png")));
    try {
        loadQueue();
    } catch (SQLException | IOException e) {
        LOG.error("Error: ", e);
    }
    this.setVisible(true);
    if (Main.firstlaunch) {
        int n = JOptionPane.showConfirmDialog(null, LANG.getString("frmMain.initialAccount.Message"),
                LANG.getString("frmMain.initialAccount.title"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (n == JOptionPane.YES_OPTION) {
            mntmAddAccountActionPerformed();
        }
    } else {
        PlaylistUpdater pu = new PlaylistUpdater(this);
        Thread updater = new Thread(pu);
        updater.start();
        AccountUpdater au = new AccountUpdater(this);
        Thread aupdater = new Thread(au);
        aupdater.start();
    }
    EditPanel edit = (EditPanel) ss1.contentPane;
    if (edit.getCmbTemplate().getModel().getSize() > 0) {
        edit.getCmbTemplate().setSelectedIndex(0);
    }
    tray = new TrayManager(this);
    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(WindowEvent e) {
            if (e.getNewState() == ICONIFIED) {
                tray.add();
                setVisible(false);
            }
            if (e.getNewState() == 7) {
                tray.add();
                setVisible(false);
            }
            if (e.getNewState() == MAXIMIZED_BOTH) {
                tray.remove();
                setVisible(true);
            }
            if (e.getNewState() == NORMAL) {
                tray.remove();
                setVisible(true);
            }
        }
    });
}

From source file:com.a544jh.kanamemory.ui.ProfileChooserPanel.java

private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
    if (JOptionPane.showConfirmDialog(this, "Are you sure?", "Delete Profile", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
        JsonFileWriter.deleteProfile((String) profilesList.getSelectedValue(), "profiles");
        populateList();/*from  w w w .  j  a v  a 2s  . com*/
    }
}

From source file:es.emergya.ui.plugins.AdminPanel.java

@Override
public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    if (cmd.indexOf("Seleccionar Tod") == 0) {
        for (int i = 0; i < table.getRowCount(); i++) {
            table.getModel().setValueAt(Boolean.TRUE, i, 0);
        }/*  www  .ja v  a2 s.co  m*/
    } else if (cmd.indexOf("Deseleccionar Tod") == 0) {
        for (int i = 0; i < table.getRowCount(); i++) {
            table.getModel().setValueAt(Boolean.FALSE, i, 0);
        }
    } else if (cmd.indexOf("Eliminar Seleccionad") == 0) {
        boolean alguno = false;
        for (int i = table.getRowCount() - 1; i >= 0 && !alguno; i--) {
            if ((Boolean) table.getModel().getValueAt(i, 0)) {
                alguno = true;
            }
        }

        if (!alguno) {
            return;
        }

        if (JOptionPane.showConfirmDialog(this, "Buttons.delete.confirm", "Selecciona una opcin",
                JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
            return;
        }
        Vector<Object> fail = new Vector<Object>();
        int total = 0;
        for (int i = table.getRowCount() - 1; i >= 0; i--) {
            if ((Boolean) table.getModel().getValueAt(i, 0)) {
                DeleteAction a = (DeleteAction) ((JButton) table.getValueAt(i, table.getColumnCount() - 1))
                        .getAction();
                total++;
                if (!a.delete(false)) {
                    fail.add(table.getValueAt(i, 1));
                }

            }
        }

        if (this.father != null) {
            this.father.refresh(null);
            PluginEventHandler.fireChange(this.father);
        }

        if (total == 0) {
            JOptionPane.showMessageDialog(this, "No hay elementos seleccionados para eliminar.", null,
                    JOptionPane.ERROR_MESSAGE);
        }

        if (fail.size() > 0) {
            JOptionPane.showMessageDialog(this, errorString + ":\n" + fail.toString() + "\n" + errorCause, null,
                    JOptionPane.ERROR_MESSAGE);
        }

    } else
        log.error("Comando no encontrado: " + cmd);
}

From source file:edu.ku.brc.services.biogeomancer.GeoCoordBGMProvider.java

public void processGeoRefData(final List<GeoCoordDataIFace> items,
        final GeoCoordProviderListenerIFace listenerArg, final String helpContextArg) {
    this.listener = listenerArg;
    this.helpContext = helpContextArg;

    UsageTracker.incrUsageCount("Tools.BioGeomancerData"); //$NON-NLS-1$

    log.info("Performing BioGeomancer lookup of selected records"); //$NON-NLS-1$

    // create a progress bar dialog to show the network progress
    final ProgressDialog progressDialog = new ProgressDialog(
            UIRegistry.getResourceString("GeoCoordBGMProvider.BIOGEOMANCER_PROGRESS"), false, true); // I18N //$NON-NLS-1$
    progressDialog.getCloseBtn().setText(getResourceString("CANCEL")); //$NON-NLS-1$
    progressDialog.setModal(true);/*from w  ww.j  av  a 2s  .c o  m*/
    progressDialog.setProcess(0, items.size());

    // XXX Java 6
    //progressDialog.setIconImage( IconManager.getImage("AppIcon").getImage());

    // use a SwingWorker thread to do all of the work, and update the GUI when done
    final SwingWorker bgTask = new SwingWorker() {
        final JStatusBar statusBar = UIRegistry.getStatusBar();
        protected boolean cancelled = false;

        @Override
        public void interrupt() {
            super.interrupt();
            cancelled = true;
        }

        @SuppressWarnings("synthetic-access") //$NON-NLS-1$
        @Override
        public Object construct() {
            // perform the BG web service call ON all rows, storing results in the rows

            int progress = 0;

            for (GeoCoordDataIFace item : items) {
                if (cancelled) {
                    break;
                }

                // get the locality data
                String localityNameStr = item.getLocalityString();

                // get the geography data
                String country = item.getCountry();
                String state = item.getState();
                String county = item.getCounty();

                log.info("Making call to BioGeomancer service: " + localityNameStr); //$NON-NLS-1$
                String bgResults;
                BioGeomancerQuerySummaryStruct bgQuerySummary;
                try {
                    bgResults = BioGeomancer.getBioGeomancerResponse(item.getGeoCoordId().toString(), country,
                            state, county, localityNameStr);
                    bgQuerySummary = BioGeomancer.parseBioGeomancerResponse(bgResults);
                } catch (IOException ex1) {
                    String warning = getResourceString("GeoCoordBGMProvider.WB_BIOGEOMANCER_UNAVAILABLE"); //$NON-NLS-1$
                    statusBar.setWarningMessage(warning, ex1);
                    log.error("A network error occurred while contacting the BioGeomancer service", ex1); //$NON-NLS-1$

                    // update the progress bar UI and move on
                    progressDialog.setProcess(++progress);
                    continue;
                } catch (Exception ex2) {
                    UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(GeoCoordBGMProvider.class,
                            ex2);
                    // right now we'll simply blame this on BG
                    // in the future we might get more specific about this error
                    String warning = getResourceString("GeoCoordBGMProvider.WB_BIOGEOMANCER_UNAVAILABLE"); //$NON-NLS-1$
                    statusBar.setWarningMessage(warning, ex2);
                    log.warn("Failed to get result count from BioGeomancer respsonse", ex2); //$NON-NLS-1$

                    // update the progress bar UI and move on
                    progressDialog.setProcess(++progress);
                    continue;
                }

                // if there was at least one result, pre-cache a map for that result
                int resCount = bgQuerySummary.results.length;
                if (resCount > 0) {
                    final int rowNumber = item.getGeoCoordId();
                    final BioGeomancerQuerySummaryStruct summaryStruct = bgQuerySummary;
                    // create a thread to go grab the map so it will be cached for later use
                    Thread t = new Thread(new Runnable() {
                        public void run() {
                            try {
                                log.info("Requesting map of BioGeomancer results for workbench row " //$NON-NLS-1$
                                        + rowNumber);
                                BioGeomancer.getMapOfQuerySummary(summaryStruct, null);
                            } catch (Exception e) {
                                UsageTracker.incrHandledUsageCount();
                                edu.ku.brc.exceptions.ExceptionTracker.getInstance()
                                        .capture(GeoCoordBGMProvider.class, e);
                                log.warn("Failed to pre-cache BioGeomancer results map", e); //$NON-NLS-1$
                            }
                        }
                    });
                    t.setName("Map Pre-Caching Thread: row " + item.getGeoCoordId()); // I18N //$NON-NLS-1$
                    log.debug("Starting map pre-caching thread"); //$NON-NLS-1$
                    t.start();
                }

                // if we got at least one result...
                if (resCount > 0) {
                    item.setXML(bgResults);
                }

                // update the progress bar UI and move on
                progressDialog.setProcess(++progress);
            }

            return null;
        }

        @Override
        public void finished() {
            statusBar.setText(getResourceString("GeoCoordBGMProvider.BIOGEOMANCER_COMPLETED")); //$NON-NLS-1$

            if (!cancelled) {
                // hide the progress dialog
                progressDialog.setVisible(false);

                // find out how many records actually had results
                List<GeoCoordDataIFace> rowsWithResults = new Vector<GeoCoordDataIFace>();
                for (GeoCoordDataIFace row : items) {
                    if (row.getXML() != null) {
                        rowsWithResults.add(row);
                    }
                }

                // if no records had possible results...
                int numRecordsWithResults = rowsWithResults.size();
                if (numRecordsWithResults == 0) {
                    statusBar.setText(getResourceString("GeoCoordBGMProvider.NO_BG_RESULTS")); //$NON-NLS-1$
                    JOptionPane.showMessageDialog(UIRegistry.getTopWindow(),
                            getResourceString("GeoCoordBGMProvider.NO_BG_RESULTS"),
                            getResourceString("NO_RESULTS"), JOptionPane.INFORMATION_MESSAGE);
                    return;
                }

                if (listener != null) {
                    listener.aboutToDisplayResults();
                }

                // ask the user if they want to review the results
                String message = String.format(
                        getResourceString("GeoCoordBGMProvider.BGM_VIEW_RESULTS_CONFIRM"), //$NON-NLS-1$
                        String.valueOf(numRecordsWithResults));
                int userChoice = JOptionPane.showConfirmDialog(UIRegistry.getTopWindow(), message,
                        getResourceString("GeoCoordBGMProvider.CONTINUE"), JOptionPane.YES_NO_OPTION);//$NON-NLS-1$

                if (userChoice != JOptionPane.YES_OPTION) {
                    statusBar.setText(getResourceString("GeoCoordBGMProvider.BIOGEOMANCER_TERMINATED")); //$NON-NLS-1$
                    return;
                }

                displayBioGeomancerResults(rowsWithResults);
            }
        }
    };

    // if the user hits close, stop the worker thread
    progressDialog.getCloseBtn().addActionListener(new ActionListener() {
        @SuppressWarnings("synthetic-access") //$NON-NLS-1$
        public void actionPerformed(ActionEvent ae) {
            log.debug("Stopping the BioGeomancer service worker thread"); //$NON-NLS-1$
            bgTask.interrupt();
        }
    });

    log.debug("Starting the BioGeomancer service worker thread"); //$NON-NLS-1$
    bgTask.start();
    UIHelper.centerAndShow(progressDialog);
}

From source file:org.jfree.chart.demo.JFreeChartDemo.java

/**
 * Exits the application, but only if the user agrees.
 *///from  www  .j  a  v  a2 s  . com
private void attemptExit() {

    final String title = this.resources.getString("dialog.exit.title");
    final String message = this.resources.getString("dialog.exit.message");
    final int result = JOptionPane.showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    if (result == JOptionPane.YES_OPTION) {
        dispose();
        System.exit(0);
    }
}

From source file:me.ryandowling.allmightybot.AllmightyBot.java

public AllmightyBot() {
    if (Files.exists(Utils.getSettingsFile())) {
        try {/* w  w w  . j  av  a  2 s  .com*/
            this.settings = GSON.fromJson(FileUtils.readFileToString(Utils.getSettingsFile().toFile()),
                    Settings.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        this.settings = new Settings();
    }

    if (!this.settings.hasInitialSetupBeenCompleted()) {
        String input = null;

        input = JOptionPane.showInputDialog(null,
                "Please enter the username of the Twitch user " + "to act " + "as the bot", "Twitch Username",
                JOptionPane.QUESTION_MESSAGE);

        if (input == null) {
            logger.error("Failed to input proper things when setting up! Do it properly next time!");
            System.exit(0);
        }

        settings.setTwitchUsername(input);

        input = JOptionPane.showInputDialog(null,
                "Please enter the IRC oauth token of the Twitch user " + "acting as the bot", "Twitch Token",
                JOptionPane.QUESTION_MESSAGE);

        if (input == null) {
            logger.error("Failed to input proper things when setting up! Do it properly next time!");
            System.exit(0);
        }

        settings.setTwitchToken(input);

        input = JOptionPane.showInputDialog(null,
                "Please enter the API token of the Twitch user " + "acting " + "as the bot", "Twitch API Token",
                JOptionPane.QUESTION_MESSAGE);

        if (input == null) {
            logger.error("Failed to input proper things when setting up! Do it properly next time!");
            System.exit(0);
        }

        settings.setTwitchApiToken(input);

        input = JOptionPane.showInputDialog(null,
                "Please enter the API client ID of the application using " + "the Twitch API",
                "Twitch API Client ID", JOptionPane.QUESTION_MESSAGE);

        if (input == null) {
            logger.error("Failed to input proper things when setting up! Do it properly next time!");
            System.exit(0);
        }

        settings.setTwitchApiClientID(input);

        input = JOptionPane.showInputDialog(null,
                "Please enter the username of the Twitch user whose "
                        + "channel you wish to join! Must be in all lowercase",
                "User To Join", JOptionPane.QUESTION_MESSAGE);

        if (input == null) {
            logger.error("Failed to input proper things when setting up! Do it properly next time!");
            System.exit(0);
        }

        settings.setTwitchChannel(input);

        input = JOptionPane.showInputDialog(null,
                "Please enter the name of the caster to display when " + "referencing them", "Casters Name",
                JOptionPane.QUESTION_MESSAGE);

        if (input == null) {
            logger.error("Failed to input proper things when setting up! Do it properly next time!");
            System.exit(0);
        }

        settings.setCastersName(input);

        input = JOptionPane.showInputDialog(null,
                "How often do you want to run the timed messages (in " + "minutes)?", "Timed Messages",
                JOptionPane.QUESTION_MESSAGE);
        try {
            settings.setTimedMessagesInterval(Integer.parseInt(input) * 60);
        } catch (NumberFormatException e) {
            input = null;
        }

        input = JOptionPane.showInputDialog(null, "How long do you want to time people out for when they post "
                + "links after 1 warning (in minutes)?", "Spam Timeouts", JOptionPane.QUESTION_MESSAGE);
        try {
            settings.setLinkTimeoutLength1(Integer.parseInt(input) * 60);
        } catch (NumberFormatException e) {
            input = null;
        }

        input = JOptionPane.showInputDialog(null,
                "How long do you want to time people out for when they post "
                        + "links after 2 and more warnings (in minutes)?",
                "Spam Timeouts", JOptionPane.QUESTION_MESSAGE);
        try {
            settings.setLinkTimeoutLength2(Integer.parseInt(input) * 60);
        } catch (NumberFormatException e) {
            input = null;
        }

        if (input == null) {
            logger.error("Failed to input proper things when setting up! Do it properly next time!");
            System.exit(0);
        }

        int reply = JOptionPane.showConfirmDialog(null,
                "Do you want the bot to announce itself on join " + "(message "
                        + "customisable in the lang.json file after startup)?",
                "Self Announce", JOptionPane.YES_NO_OPTION);
        if (reply != JOptionPane.YES_OPTION) {
            settings.setAnnounceOnJoin(false);
        }

        this.settings.initialSetupComplete();
        this.firstTime = true;
    }
}