Example usage for javax.swing JOptionPane OK_OPTION

List of usage examples for javax.swing JOptionPane OK_OPTION

Introduction

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

Prototype

int OK_OPTION

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

Click Source Link

Document

Return value form class method if OK is chosen.

Usage

From source file:Main.java

/**
 * Displays a {@link JOptionPane} as a Confirm Dialog with OK and CANCEL buttons.
 * /*from   w w  w  .j ava 2s. c o  m*/
 * @param title The title of the Dialog.
 * @param message The message of the Dialog.
 * @return "ok" or "cancel" if clicked on the respective buttons.
 */
public static String showConfirmationDialogWithOkCancelButtons(String title, String message) {
    int result = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    if (result == JOptionPane.OK_OPTION)
        return "ok";
    if (result == JOptionPane.CANCEL_OPTION)
        return "cancel";
    return null;
}

From source file:Main.java

public static WindowAdapter createConfirmOnExitAdapter(final JFrame frame, final String title,
        final String message) {
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    return new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent ev) {
            int result = JOptionPane.showConfirmDialog(frame, message, title, JOptionPane.YES_OPTION);
            if (result == JOptionPane.OK_OPTION) {
                frame.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                System.exit(0);/*from www.  j  a v a 2 s.  c o m*/
            }
        }
    };
}

From source file:commonline.query.gui.action.ClearDatabaseAction.java

public void actionPerformed(ActionEvent actionEvent) {
    if (JOptionPane.showConfirmDialog(parent, "Are you sure you want to clear the databases?", "Clear DB",
            JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) {
        SwingWorker worker = new SwingWorker<Void, Void>() {
            protected Void doInBackground() throws Exception {
                for (RecordParserDataSource dataSource : dataSources) {
                    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
                    for (RecordLayoutTableInfo tableInfo : dataSource.getTableInfos()) {
                        try {
                            jdbcTemplate.execute("delete from " + tableInfo.getTableName());
                        } catch (Exception err) {
                            throw new RuntimeException("Problem clearing table:" + tableInfo.getTableName()
                                    + ", in DB:" + dataSource.getUrl(), err);
                        }//from w  w w . j  ava2 s.  c  o  m
                    }
                }
                return null;
            }
        };
        worker.execute();
    }
}

From source file:Main.java

@Override
public void actionPerformed(ActionEvent e) {
    MyPanel patientPicker = new MyPanel();
    int result = JOptionPane.showConfirmDialog(swingFoo, patientPicker, "Select Something",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.OK_OPTION) {
        swingFoo.setFileFieldText(patientPicker.getSelectedItem());
    }/*from   www.j  a  va 2 s.  co m*/
    patientPicker.setVisible(true);
}

From source file:com.gs.obevo.util.inputreader.DialogInputReader.java

@Override
public String readLine(String promptMessage) {
    final JTextField juf = new JTextField();
    JOptionPane juop = new JOptionPane(juf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog userDialog = juop.createDialog(promptMessage);
    userDialog.addComponentListener(new ComponentAdapter() {
        @Override/*from  w  w  w  . j av  a2 s  .co m*/
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    juf.requestFocusInWindow();
                }
            });
        }
    });
    userDialog.setVisible(true);
    int uresult = (Integer) juop.getValue();
    userDialog.dispose();
    String userName = null;
    if (uresult == JOptionPane.OK_OPTION) {
        userName = new String(juf.getText());
    }

    if (StringUtils.isEmpty(userName)) {
        return null;
    } else {
        return userName;
    }
}

From source file:com.pos.spatobiz.app.view.desktop.SpatoBizApplication.java

@Override
public boolean canClose() {
    if (DesktopUtilities.showConfirmMessage(this, getTitle(), applicationContext.getMessage("application.close",
            null, Locale.getDefault())) == JOptionPane.OK_OPTION) {
        return true;
    }/*  w w w .  j a v  a2  s.c o  m*/
    return false;
}

From source file:mysynopsis.FTPUploader.java

public static void display() throws IOException {

    JTextField address = new JTextField(server);
    JTextField username = new JTextField(user);
    JPasswordField password = new JPasswordField(pass);
    JTextField directory = new JTextField(dir);

    JPanel panel = new JPanel(new GridLayout(10, 1));
    panel.add(new JLabel("Server Address:"));
    panel.add(address);//from  ww w.  j a v a2  s  .  co  m
    panel.add(new JLabel("Username:"));
    panel.add(username);
    panel.add(new JLabel("Password:"));
    panel.add(password);
    panel.add(new JLabel("Upload Directory:"));
    panel.add(directory);

    int result;

    /*JOptionPane pane = new JOptionPane(panel,JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
    JDialog dialog = pane.createDialog(MotherFrame.mframe, "FTP Upload Wizard - My Synopsis");
    dialog.setSize(new Dimension(300,300));
    dialog.setVisible(true);*/

    result = JOptionPane.showConfirmDialog(MotherFrame.mframe, panel, "FTP Upload Wizard",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

    if (result == JOptionPane.OK_OPTION) {

        server = address.getText();
        user = username.getText();
        pass = new String(password.getPassword());
        //    System.out.println(pass);
        dir = directory.getText();

        JOptionPane.showMessageDialog(MotherFrame.mframe, "Press OK to start FTP Upload");

        HTMLWriter.writeHTML();

        JOptionPane.showMessageDialog(MotherFrame.mframe, uploadWizard());

    } else {
        //  System.out.println("Cancelled");
    }
}

From source file:com.mc.printer.model.panel.task.BuildModelTask.java

@Override
public Object doBackgrounp() {
    javax.swing.JTabbedPane tabs = AutoPrinterApp.getMainView().getMainWorkPanel();
    if (tabs != null) {
        if (tabs.getSelectedIndex() >= 0) {
            Component selectedcom = tabs.getSelectedComponent();
            if (selectedcom instanceof CanvasWork) {
                CanvasWork selectPanel = (CanvasWork) selectedcom;
                FormBeans beansForm = selectPanel.getBeansForm();

                /**/
                if (beansForm.getHeightcm() == 0 || beansForm.getWidthcm() == 0) {
                    int res = BaseMessage.CONFIRM(
                            "?\r\nA4.");
                    if (res != JOptionPane.OK_OPTION) {
                        return null;
                    }//from ww  w  .  j a v  a2  s .  co  m
                }

                String imagePath = beansForm.getImgpath();
                HashMap<String, ComponentBean> parameterMap = selectPanel.getSavedForms();
                if (parameterMap.size() > 0) {
                    Set set = parameterMap.keySet();
                    boolean foundKey = false;
                    //???
                    List<ComponentBean> beans = new ArrayList();
                    Iterator it = set.iterator();
                    while (it.hasNext()) {
                        ComponentBean com = parameterMap.get(it.next().toString());
                        beans.add(com);
                        if (com.isIskey()) {
                            foundKey = true;
                        }
                    }
                    beansForm.setElements(beans);
                    //
                    //                        if (!foundKey) {
                    //                            BaseMessage.ERROR("PRIMARY KEY.");
                    //                            return null;
                    //                        }

                    BaseFileChoose fileChoose = new BaseFileChoose("?",
                            new String[] { Constants.MODEL_SUFFIX }, AutoPrinterApp.getMainFrame());
                    String selectedPath = fileChoose.showSaveDialog();
                    if (!selectedPath.trim().equals("")) {

                        //get formname
                        selectedPath = selectedPath + File.separator + beansForm.getFormname();
                        //String time=DateHelper.format(new Date(), "yyyyMMddHHmmss");
                        String finalZip = selectedPath;
                        if (!selectedPath.endsWith("." + Constants.MODEL_SUFFIX)) {
                            finalZip = selectedPath + "." + Constants.MODEL_SUFFIX;
                        }

                        String tempDir = selectedPath + File.separator + Constants.MODEL_TEMP_DIR;

                        File imageFile = new File(imagePath);

                        String xmlPath = tempDir + File.separator + imageFile.getName() + ".xml";
                        XMLHelper helper = new XMLHelper(xmlPath, beansForm);
                        try {
                            helper.write();
                        } catch (JAXBException ex) {
                            ex.printStackTrace();
                            logger.error(ex.getMessage());
                            return ex;
                        }

                        File paramFile = new File(xmlPath);
                        if (paramFile.isFile() && paramFile.exists()) {
                            try {
                                FileUtils.copyFileToDirectory(imageFile, new File(tempDir));
                                ZipHelper.createZip(tempDir, finalZip);
                                return "??.\r\n" + finalZip;
                            } catch (IOException ex) {
                                ex.printStackTrace();
                                logger.error(ex.getMessage());
                                return ex;
                            } finally {
                                try {
                                    FileUtils.deleteDirectory(new File(selectedPath));
                                } catch (IOException ex) {
                                    ex.printStackTrace();
                                    logger.error(ex.getMessage());
                                    return ex;
                                }
                            }
                        }
                    }
                } else {
                    return "??.";
                }
            } else {
                return "??????.";
            }
        } else {
            return ".";
        }
    } else {
        return ".";
    }
    return null;
}

From source file:be.fedict.eid.tsl.Pkcs11CallbackHandler.java

private char[] getPin() {
    Box mainPanel = Box.createVerticalBox();

    Box passwordPanel = Box.createHorizontalBox();
    JLabel promptLabel = new JLabel("eID PIN:");
    passwordPanel.add(promptLabel);/*from  w w w.  ja  v a 2  s  .c o  m*/
    passwordPanel.add(Box.createHorizontalStrut(5));
    JPasswordField passwordField = new JPasswordField(8);
    passwordPanel.add(passwordField);
    mainPanel.add(passwordPanel);

    Component parentComponent = null;
    int result = JOptionPane.showOptionDialog(parentComponent, mainPanel, "eID PIN?",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    if (result == JOptionPane.OK_OPTION) {
        char[] pin = passwordField.getPassword();
        return pin;
    }
    throw new RuntimeException("operation canceled.");
}

From source file:gov.nih.nci.nbia.StandaloneDMV1.java

void checkCompatibility() {
    if (!serverUrl.endsWith("Servlet")) {
        Object[] options = { "OK" };

        int n = JOptionPane.showOptionDialog(frame, serverVersionMsg, "Incompatible Server Notification",
                JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
        System.exit(n);/*  ww  w.  j  a  va  2s  .co m*/
    }
}