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:com.nubits.nubot.launch.toolkit.LaunchUI.java

private String askUser() {
    //Create Options for option dialog
    String path = "";

    // Set cross-platform Java L&F (also called "Metal")
    try {/*from w  w w  .  j av a  2 s  . c  om*/
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());

        final ImageIcon icon = new ImageIcon(local_path + "/" + ICON_PATH);

        //Ask the user to ask for scratch
        Object[] options = { "Import existing JSON option file", "Configure the bot from scratch" };

        int n = JOptionPane.showOptionDialog(new JFrame(), "Chose one of the following options:",
                "NuBot UI Launcher", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, icon, //do not use a custom Icon
                options, //the titles of buttons
                options[0]); //default button title

        if (n == JOptionPane.YES_OPTION) {

            //Prompt user to chose a file.
            JFileChooser fileChooser = createFileChoser();

            int result = fileChooser.showOpenDialog(new JFrame());
            if (result == JFileChooser.APPROVE_OPTION) {
                File selectedFile = fileChooser.getSelectedFile();
                path = selectedFile.getAbsolutePath();
                LOG.info("Option file selected : " + path);
            } else {
                LOG.info("Closing Launch UI utility.");
                System.exit(0);
            }
        }
    } catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException
            | InstantiationException e) {
        LOG.error(e.toString());
    }

    return path;
}

From source file:javaapplication3.ObjetDialog.java

public void ObjetDialogStart() {
    instance = new InstanceCall();
    setTitle("Add Information about" + new File(BPath.getText()).getName());
    hideErrorFields();/*from  ww w .j  a  v a2  s  .c  om*/
    Date date = Calendar.getInstance().getTime();
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    this.dateRunTxt.setText(sdf.format(date));
    this.setLocationRelativeTo(null);
    //search database for buildName
    //File BPathfile = new File(BPath.getText().replace("\\", "\\\\"));
    setVisible(true);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent we) {
            String ObjButtons[] = { "Yes", "No" };
            int PromptResult = JOptionPane.showOptionDialog(null, "Save as an Open Build?", "Save",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, ObjButtons, ObjButtons[1]);
            if (PromptResult == JOptionPane.YES_OPTION) {
                gatherScrapThenExit();
                PrinterBuild.selectAllFiles("Objet");
                dispose();
            } else {
                ResultSet r = ObjetMain.dba.searchPendingByBuildName(new File(BPath.getText()).getName());
                try {
                    while (r.next()) {
                        ObjetMain.dba.updatePendingJobsBuildName(r.getString("buildName"),
                                r.getString("fileName"));
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(ObjetDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                ResultSet s = ObjetMain.dba.searchObjetByBuildName(new File(BPath.getText()).getName());
                try {
                    while (s.next()) {
                        ObjetMain.dba.deleteByBuildName(s.getString("buildName"), "objet");
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(ObjetDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                dispose();
            }
        }
    });
}

From source file:javaapplication3.ZCorpDialog.java

public void ZCorpDialogStart() {
    instance = new InstanceCall();
    setTitle("Add Information about" + new File(BPath.getText()).getName());
    hideErrorFields();/*from ww w .  j a v  a2 s . c  om*/
    Date date = Calendar.getInstance().getTime();
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    this.dateRunTxt.setText(sdf.format(date));
    this.setLocationRelativeTo(null);
    //search database for buildName
    //File BPathfile = new File(BPath.getText().replace("\\", "\\\\"));
    setVisible(true);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent we) {
            String ObjButtons[] = { "Yes", "No" };
            int PromptResult = JOptionPane.showOptionDialog(null, "Save as an Open Build?", "Save",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, ObjButtons, ObjButtons[1]);
            if (PromptResult == JOptionPane.YES_OPTION) {
                gatherScrapThenExit();
                PrinterBuild.selectAllFiles("ZCorp");
                dispose();
            } else {
                ResultSet r = ZCorpMain.dba.searchPendingByBuildName(new File(BPath.getText()).getName());
                try {
                    while (r.next()) {
                        ZCorpMain.dba.updatePendingJobsBuildName(r.getString("buildName"),
                                r.getString("fileName"));
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(ZCorpDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                ResultSet s = ZCorpMain.dba.searchZCorpByBuildName(new File(BPath.getText()).getName());
                try {
                    while (s.next()) {
                        ZCorpMain.dba.deleteByBuildName(s.getString("buildName"), "zcorp");
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(ZCorpDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                dispose();
            }
        }
    });
}

From source file:de.peterspan.csv2db.AppWindow.java

private void initialize() {
    frame = new JFrame();

    frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage());

    AppWindow._frame = frame;/*from  w  w w  .  ja  v  a  2  s  .c  o  m*/
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (reallyExit() == JOptionPane.YES_OPTION) {
                SingleInstance.release();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        }
    });

    frame.setTitle(Messages.getString("AppWindow.0") + " " + Messages.getString("AppWindow.version.code")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    frame.setLocationRelativeTo(null);
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu(Messages.getString("AppWindow.1")); //$NON-NLS-1$
    menuBar.add(mnFile);

    JMenuItem mntmExit = new JMenuItem(Messages.getString("AppWindow.3")); //$NON-NLS-1$
    mntmExit.setIcon(Icons.IC_LOGOUT_SMALL);
    mntmExit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);

        }
    });
    mnFile.add(mntmExit);

    JMenu mnEdit = new JMenu(Messages.getString("AppWindow.4")); //$NON-NLS-1$
    menuBar.add(mnEdit);

    JMenuItem mntmOptions = new JMenuItem(Messages.getString("AppWindow.5")); //$NON-NLS-1$
    mntmOptions.setIcon(Icons.IC_PREFERENCES_SYSTEM_SMALL);
    mntmOptions.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //            new OptionsDialog(frame);
        }
    });
    mnEdit.add(mntmOptions);

    JMenu mnHelp = new JMenu(Messages.getString("AppWindow.6")); //$NON-NLS-1$
    menuBar.add(mnHelp);

    JMenuItem mntmAbout = new JMenuItem(Messages.getString("AppWindow.7")); //$NON-NLS-1$
    mntmAbout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                new AboutDialog(frame);
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block

                e.printStackTrace();
            }
        }
    });
    mnHelp.add(mntmAbout);

    createContent();

    DialogUtil.getInstance().setMainFrame(frame);

}

From source file:com.floreantpos.actions.NewBarTabAction.java

@Override
public void actionPerformed(ActionEvent e) {
    PaymentTypeSelectionDialog paymentTypeSelectionDialog = new PaymentTypeSelectionDialog();
    paymentTypeSelectionDialog.setCashButtonVisible(false);
    paymentTypeSelectionDialog.pack();//from w ww  .  ja  v  a  2 s.  co m
    paymentTypeSelectionDialog.setLocationRelativeTo(parentComponent);
    paymentTypeSelectionDialog.setVisible(true);

    if (paymentTypeSelectionDialog.isCanceled()) {
        return;
    }

    selectedPaymentType = paymentTypeSelectionDialog.getSelectedPaymentType();

    String symbol = CurrencyUtil.getCurrencySymbol();
    String message = symbol + CardConfig.getBartabLimit() + Messages.getString("NewBarTabAction.3"); //$NON-NLS-1$

    int option = POSMessageDialog.showYesNoQuestionDialog(parentComponent, message,
            Messages.getString("NewBarTabAction.4")); //$NON-NLS-1$
    if (option != JOptionPane.YES_OPTION) {
        return;
    }

    SwipeCardDialog dialog = new SwipeCardDialog(this);
    dialog.setTitle(Messages.getString("NewBarTabAction.0")); //$NON-NLS-1$
    dialog.pack();
    dialog.open();
}

From source file:de.bley.word.menu.GuiMenu.java

private void addListener() {

    button.addActionListener(new ActionListener() {
        @Override/* ww  w. j a  v  a 2  s  . c o m*/
        public void actionPerformed(ActionEvent e) {
            saveData();
            refreshList();
        }
    });

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {

            if (!textfield.getText().equals("") && !textfield.getText().equals(PropertieManager.getInstance()
                    .getZuordnung().getReader().readFile(zuordnung.getPath().getFilepath()))) {

                int confirmed = JOptionPane.showConfirmDialog(null, "Daten speichern?", "Beenden",
                        JOptionPane.YES_NO_OPTION);

                if (confirmed == JOptionPane.YES_OPTION) {
                    saveData();
                }
            }
        }
    });

}

From source file:com.aw.swing.mvp.ui.msg.MessageDisplayerImpl.java

public static boolean showConfirmMessage(Component parentContainer, String messageConfirm, int icon,
        int defaultButton) {
    ProcessMsgBlocker.instance().removeMessage();
    int result = JOptionPane.showOptionDialog(parentContainer, messageConfirm, GENERIC_MESSAGE_TITLE,
            JOptionPane.YES_NO_OPTION, icon, null, options, options[defaultButton]);
    return (result == JOptionPane.YES_OPTION);
}

From source file:edu.ku.brc.specify.config.init.RegisterSpecify.java

/**
 * @param title//from w w  w.  j  a  v a2 s.c o  m
 * @return
 */
private boolean askToReg(final String typeTitle, final String typeName) {
    Object[] options = { getResourceString("YES"), //$NON-NLS-1$
            getResourceString("NO") //$NON-NLS-1$
    };
    int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
            getLocalizedMessage("SpReg.DO_REG", typeTitle, typeName), //$NON-NLS-1$
            getResourceString("SpReg.DO_REG_TITLE"), //$NON-NLS-1$
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

    return userChoice == JOptionPane.YES_OPTION;
}

From source file:de.atomfrede.tools.evalutation.ui.AppWindow.java

/**
 * Initialize the contents of the frame.
 *///from ww  w  .  j ava2s  . com
private void initialize() {
    log.info("Plant Evaluator started");
    frame = new JFrame();

    frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage());

    AppWindow._frame = frame;
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (reallyExit() == JOptionPane.YES_OPTION) {
                SingleInstance.release();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        }
    });

    frame.setTitle(Messages.getString("AppWindow.0") + " " + Messages.getString("AppWindow.version.code")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    frame.setLocationRelativeTo(null);
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu(Messages.getString("AppWindow.1")); //$NON-NLS-1$
    menuBar.add(mnFile);

    JMenuItem mntmExit = new JMenuItem(Messages.getString("AppWindow.3")); //$NON-NLS-1$
    mntmExit.setIcon(Icons.IC_LOGOUT_SMALL);
    mntmExit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);

        }
    });
    mnFile.add(mntmExit);

    JMenu mnEdit = new JMenu(Messages.getString("AppWindow.4")); //$NON-NLS-1$
    menuBar.add(mnEdit);

    JMenuItem mntmOptions = new JMenuItem(Messages.getString("AppWindow.5")); //$NON-NLS-1$
    mntmOptions.setIcon(Icons.IC_PREFERENCES_SYSTEM_SMALL);
    mntmOptions.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new OptionsDialog(frame);
        }
    });
    mnEdit.add(mntmOptions);

    JMenu mnTools = new JMenu(Messages.getString("AppWindow.mnTools.text")); //$NON-NLS-1$
    menuBar.add(mnTools);

    JMenuItem mntmPostprocessing = new JMenuItem(Messages.getString("AppWindow.mntmPostprocessing.text")); //$NON-NLS-1$
    mntmPostprocessing.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
        }
    });
    mnTools.add(mntmPostprocessing);

    JMenuItem mntmPlot = new JMenuItem(Messages.getString("AppWindow.mntmPlot.text")); //$NON-NLS-1$
    mntmPlot.setIcon(Icons.IC_TOOL_PLOT_SMALL);
    mntmPlot.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            DialogUtil.getInstance().showPlotTypeSelection();
        }
    });

    mnTools.add(mntmPlot);

    JMenu mnHelp = new JMenu(Messages.getString("AppWindow.6")); //$NON-NLS-1$
    menuBar.add(mnHelp);

    JMenuItem mntmAbout = new JMenuItem(Messages.getString("AppWindow.7")); //$NON-NLS-1$
    mntmAbout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                new AboutDialog(frame);
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block

                e.printStackTrace();
            }
        }
    });
    mnHelp.add(mntmAbout);

    createContent();

    DialogUtil.getInstance().setMainFrame(frame);

}

From source file:GUI.MainJF.java

public void LlenarTabla() {
    String[] columnNames = { "ID", "Nombre", "Email", "Edad", "Tipo", "", "" };
    Object[][] data = null;//from w ww. j a  v a 2 s. c o m
    DefaultTableModel model = new DefaultTableModel(data, columnNames);

    HttpResponse response;
    response = JSON.request(Config.URL + "usuarios/listar.json");
    JSONObject jObject = JSON.JSON(response);
    try {
        JSONArray jsonArr = jObject.getJSONArray("data");

        for (int i = 0; i < jsonArr.length(); i++) {
            JSONObject data_json = jsonArr.getJSONObject(i);
            model.addRow(
                    new Object[] { data_json.get("idUsuario").toString(), data_json.get("nombre").toString(),
                            data_json.get("email").toString(), data_json.get("edad").toString(),
                            data_json.get("descripcion").toString(), "Editar", "Eliminar" });
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    tb_usuarios.setModel(model);

    Action editar = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {

            JTable table = (JTable) e.getSource();
            int modelRow = Integer.valueOf(e.getActionCommand());

            String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0);
            String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1);
            String email = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 2);
            String edad = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 3);
            String tipo = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 4);

            FormUsuarios U = new FormUsuarios();

            U.setID(id);
            U.setNombre(nombre);
            U.setEmail(email);
            U.setEdad(edad);
            U.setTipo(tipo);

            U.setLocationRelativeTo(null);
            U.setVisible(true);
        }
    };
    ButtonColumn botonEditar = new ButtonColumn(tb_usuarios, editar, 5);
    botonEditar.setMnemonic(KeyEvent.VK_D);

    Action eliminar = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JTable table = (JTable) e.getSource();
            int modelRow = Integer.valueOf(e.getActionCommand());
            String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0);
            String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1);

            int rs = JOptionPane.showConfirmDialog(null,
                    "Estas seguro que deseas eliminas el usuario: " + nombre + " ?", "Eliminar",
                    JOptionPane.YES_NO_OPTION);
            if (rs == JOptionPane.YES_OPTION) {

                List<NameValuePair> parametros = new ArrayList<NameValuePair>();
                parametros.add(new BasicNameValuePair("idUsuario", id));

                HttpResponse response = JSON.request(Config.URL + "usuarios/eliminar.json", parametros);
                JSONObject jObject = JSON.JSON(response);
                int code = Integer.parseInt(jObject.get("code").toString());

                /*if(code == 201){
                JOptionPane.showMessageDialog(null, "Usuario eliminado");
                //((DefaultTableModel)table.getModel()).removeRow(modelRow);
                }else{
                JOptionPane.showMessageDialog(null, "Error eliminar Usuario");
                }*/
            }

        }
    };
    ButtonColumn botonEliminar = new ButtonColumn(tb_usuarios, eliminar, 6);
    botonEliminar.setMnemonic(KeyEvent.VK_D);
    model.fireTableDataChanged();

}