Example usage for javax.swing JOptionPane showConfirmDialog

List of usage examples for javax.swing JOptionPane showConfirmDialog

Introduction

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

Prototype

public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType,
        int messageType) throws HeadlessException 

Source Link

Document

Brings up a dialog where the number of choices is determined by the optionType parameter, where the messageType parameter determines the icon to display.

Usage

From source file:br.com.pontocontrol.controleponto.ControlePonto.java

public static void solicitarLogin() {
    String usuario;/* w w w .j a v a  2 s.  c  om*/
    do {
        usuario = JOptionPane.showInputDialog(null, "Informe seu usurio:", "Identificao",
                JOptionPane.INFORMATION_MESSAGE);
        if (StringUtils.isBlank(usuario)) {
            JOptionPane.showMessageDialog(null, "Informe um login de usurio.", "Validao falhou.",
                    JOptionPane.ERROR_MESSAGE);
        }
    } while (StringUtils.isBlank(usuario));
    switch (SessaoManager.getInstance().autenticar(usuario)) {
    case SessaoManager.LOGIN_STATUS.OK:

        break;
    case SessaoManager.LOGIN_STATUS.USUARIO_NAO_EXISTE:
        int opt = JOptionPane.showConfirmDialog(null,
                format("O usurio com o login informado \"%s\" no existe, deseja criar um novo usurio?",
                        usuario),
                "Usurio no encontrado.", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        if (JOptionPane.YES_OPTION == opt) {
            ConfiguracoesUsuario configuracoesUsuario = new ConfiguracoesUsuario(usuario);
            SessaoManager.getInstance().criarUsuario(configuracoesUsuario);
            SessaoManager.getInstance().autenticar(usuario);
        }
        break;
    default:

        break;
    }
}

From source file:Main.java

/**
 * Asks the user for confirmation.//from w  w  w  .  j  a  v a  2s. com
 * 
 * @param aWindow
 *          the parent window of the confirmation dialog;
 * @param aMessage
 *          the message to display in the confirmation dialog;
 * @param aTitle
 *          the title to display in the confirmation dialog.
 * @return <code>true</code> if the user acknowledged the confirmation,
 *         <code>false</code> otherwise.
 */
public static boolean askConfirmation(final Window aWindow, final String aMessage, final String aTitle) {
    return JOptionPane.showConfirmDialog(aWindow, aMessage, aTitle, JOptionPane.YES_NO_OPTION,
            JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION;
}

From source file:GUI.VentanaPrincipal.java

public void SalirPrograma() {
    if ((JOptionPane.showConfirmDialog(this, "Realmente desea salir de la aplicacin?",
            "Salir del Monitor 1 de Bases de Datos", JOptionPane.YES_NO_OPTION,
            JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION)) {
        System.exit(0);/*from   w  w w .j  a va2  s .c o  m*/
    }
}

From source file:au.org.ala.delta.ui.MessageDialogHelper.java

/**
 * Uses JOptionPane.showInputDialog to display the supplied (multi-line) message and return the
 * user selection./*w  w w .  java2s . c  om*/
 * @param parent the parent component used to display the JOptionPane.
 * @param title the title for the option pane.
 * @param text the message text to display on the option pane.  Multi-line messages should 
 * use the "\n" character.
 * @param numColumns the column position to wrap the text at.
 * @return the value returned from the JOptionPane showConfirmDialog method (i.e the user selection)
 */
public static int showConfirmDialog(Component parent, String title, String text, int numColumns) {
    JTextArea messageDisplay = createMessageDisplay(text, numColumns);
    return JOptionPane.showConfirmDialog(parent, messageDisplay, title, JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);
}

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 www  . jav a2s. 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:groovesquid.UpdateCheckThread.java

@Override
public void run() {
    UpdateCheck updateCheck = gson.fromJson(getFile(updateFile), UpdateCheck.class);
    if (updateCheck.getClients() != null)
        Grooveshark.setClients(updateCheck.getClients());

    if (Utils.compareVersions(updateCheck.getVersion(), Main.getVersion()) > 0) {
        if (JOptionPane.showConfirmDialog(null,
                "New version (v" + updateCheck.getVersion()
                        + ") is available! Do you want to download the new version (recommended)?",
                "New version", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) {
            try {
                Desktop.getDesktop().browse(java.net.URI.create("http://groovesquid.com/#download"));
            } catch (IOException ex) {
                log.log(Level.SEVERE, null, ex);
            }/*from   ww w  .  ja va2s  .  c  om*/
        }
    }
}

From source file:oct.util.Util.java

public static OCT getOCT(BufferedImage octImage, OCTAnalysisUI octAnalysisUI, String octFileName) {
    boolean exit = false;
    //ask the user for the x-scale
    double xscale = 0;
    do {/*from   w  w  w .  j  av  a 2  s. co  m*/
        String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT X-axis scale (microns per pixel):",
                "X-Scale input", JOptionPane.QUESTION_MESSAGE);
        if (!(res == null || res.isEmpty())) {
            xscale = Util.parseNumberFromInput(res);
        }
        if (res == null || res.isEmpty() || xscale <= 0) {
            exit = JOptionPane.showConfirmDialog(octAnalysisUI,
                    "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.",
                    "Input Error", JOptionPane.YES_NO_OPTION,
                    JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION;
        }
    } while (!exit && xscale <= 0);
    if (exit) {
        return null;
    }
    //ask the user for the y-scale
    double yscale = 0;
    do {
        String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT Y-axis scale (microns per pixel):",
                "Y-Scale input", JOptionPane.QUESTION_MESSAGE);
        if (!(res == null || res.isEmpty())) {
            yscale = Util.parseNumberFromInput(res);
        }
        if (res == null || res.isEmpty() || yscale <= 0) {
            exit = JOptionPane.showConfirmDialog(octAnalysisUI,
                    "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.",
                    "Input Error", JOptionPane.YES_NO_OPTION,
                    JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION;
        }
    } while (!exit && yscale <= 0);
    if (exit) {
        return null;
    }

    //store values and return OCT object
    OCTAnalysisManager octMngr = OCTAnalysisManager.getInstance();
    octMngr.setXscale(xscale);
    octMngr.setYscale(yscale);
    return new OCT(octImage, octFileName);
}

From source file:io.github.jeremgamer.editor.panels.Actions.java

public Actions(final JFrame frame, final ActionPanel ap) {
    this.frame = frame;

    this.setBorder(BorderFactory.createTitledBorder(""));
    JButton add = null;/* w w w  .j a  v a2s. c o  m*/
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog(null, "Nommez l'action :", "Crer une action",
                        JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new ActionSave(name);
                    OtherPanel.updateLists();
                    ButtonPanel.updateLists();
                    ActionPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (actionList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/actions/"
                            + actionList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog(null,
                            "tes-vous sr de vouloir supprimer cette action?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        if (actionList.getSelectedValue().equals(ap.getFileName())) {
                            ap.setFileName("");
                        }
                        ap.hide();
                        file.delete();
                        data.remove(actionList.getSelectedIndex());
                        OtherPanel.updateLists();
                        ButtonPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    actionList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(actionList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);
    OtherPanel.updateLists();
}

From source file:ca.sqlpower.wabit.swingui.action.DeleteWabitServerWorkspaceAction.java

public void actionPerformed(ActionEvent e) {
    try {//from   w w  w.  ja  va2  s. co m
        WabitSwingSessionImpl activeSwingSession = (WabitSwingSessionImpl) context.getActiveSwingSession();
        if (activeSwingSession == null) {
            JOptionPane.showMessageDialog(context.getFrame(), "That button refreshes the current workspace,\n"
                    + "but there is no workspace selected right now.");
            return;
        }
        int choice = JOptionPane.showConfirmDialog(context.getFrame(),
                "By deleting this workspace, " + "you will not be able to recover any of its contents.\n"
                        + "Are you sure you want to delete it?",
                "Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

        if (choice == JOptionPane.YES_OPTION) {
            activeSwingSession.delete();
        }
    } catch (ClientProtocolException ex) {
        throw new RuntimeException(ex);
    } catch (URISyntaxException ex) {
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:io.github.jeremgamer.editor.panels.Labels.java

public Labels(final JFrame frame, final LabelPanel lp, final PanelSave ps) {
    this.frame = frame;

    this.setBorder(BorderFactory.createTitledBorder(""));
    JButton add = null;//w w  w  .  j a v a2  s . c  o m
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(labelList),
                        "Nommez le label :", "Crer un label", JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new LabelSave(name);
                    ActionPanel.updateLists();
                    OtherPanel.updateLists();
                    PanelsPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (labelList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/labels/"
                            + labelList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(labelList),
                            "tes-vous sr de vouloir supprimer ce label?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        File dir = new File("projects/" + Editor.getProjectName() + "/panels");
                        for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            if (!f.isDirectory()) {
                                try {
                                    ps.load(f);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                for (String section : ps
                                        .getSectionsContaining(labelList.getSelectedValue() + " (Label)")) {
                                    ps.removeSection(section);
                                    try {
                                        ps.save(f);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                        if (labelList.getSelectedValue().equals(lp.getFileName())) {
                            lp.setFileName("");
                        }
                        lp.hide();
                        file.delete();
                        data.remove(labelList.getSelectedIndex());
                        ActionPanel.updateLists();
                        OtherPanel.updateLists();
                        PanelsPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    labelList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    lp.show();
                    lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            lp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            lp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        lp.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    lp.show();
                    lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            lp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            lp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        lp.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(labelList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);

}