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.proyecto.vista.MantenimientoPeriodo.java

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed
    // TODO add your handling code here:
    accion = Controlador.ELIMINAR;/*from  w  w  w  . j a va  2 s. c om*/
    if (tblperiodo.getSelectedRow() != -1) {

        Integer codigo = tblperiodo.getSelectedRow();

        Periodo periodo = periodoControlador.buscarPorId(lista.get(codigo).getId());

        if (periodo != null) {
            if (JOptionPane.showConfirmDialog(null, "Desea Eliminar el Periodo?", "Mensaje del Sistema",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                int[] filas = tblperiodo.getSelectedRows();
                for (int i = 0; i < filas.length; i++) {
                    Periodo periodo2 = lista.get(filas[0]);
                    lista.remove(periodo2);
                    periodoControlador.setSeleccionado(periodo2);
                    periodoControlador.accion(accion);
                }
                if (periodoControlador.accion(accion) == 3) {
                    JOptionPane.showMessageDialog(null, "Periodo eliminado correctamente",
                            "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);

                } else {
                    JOptionPane.showMessageDialog(null, "Periodo no eliminada", "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Periodo no eliminada", "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } else {
        JOptionPane.showMessageDialog(null, "Debe seleccionar un Periodo", "Mensaje del Sistema",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.tiempometa.muestradatos.JMuestraDatos.java

private void clearTagsMenuItemActionPerformed(ActionEvent e) {
    int response = JOptionPane.showConfirmDialog(this,
            "Seguro que desea borrar todos los tags? Esta operacin no se puede deshacer", "Borrar tags",
            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
    if (response == JOptionPane.YES_OPTION) {
        try {/*from   www  .ja  va  2 s .  c  o  m*/
            rfidDao.deleteAll();
            JOptionPane.showMessageDialog(this, "Se borraron todos los tags", "Despejar Tags",
                    JOptionPane.PLAIN_MESSAGE);
        } catch (SQLException e1) {
            JOptionPane.showMessageDialog(this, "Error despejando tags " + e1.getMessage(), "Despejar Tags",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:com.biosis.biosislite.vistas.inventario.MantenimientoCampo.java

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed
    // TODO add your handling code here:
    accion = AbstractControlador.ELIMINAR;
    if (tblclase.getSelectedRow() != -1) {

        Integer id = tblclase.getSelectedRow();

        Campo campo = campoControlador.buscarPorId(lista.get(id).getId());

        if (campo != null) {
            if (JOptionPane.showConfirmDialog(null, "Desea Eliminar el Campo?", "Mensaje del Sistema",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                int[] filas = tblclase.getSelectedRows();
                for (int i = 0; i < filas.length; i++) {
                    Campo campo2 = lista.get(filas[0]);
                    lista.remove(campo2);
                    campoControlador.setSeleccionado(campo2);
                    campoControlador.accion(accion);
                }//w  w w .  j a v a2 s  .  c  o  m
                if (campoControlador.accion(accion) == 3) {
                    JOptionPane.showMessageDialog(null, "Campo eliminada correctamente", "Mensaje del Sistema",
                            JOptionPane.INFORMATION_MESSAGE);

                } else {
                    JOptionPane.showMessageDialog(null, "Campo no eliminada", "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Campo no eliminada", "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } else {
        JOptionPane.showMessageDialog(null, "Debe seleccionar un Campo de la lista", "Mensaje del Sistema",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.mgmtp.perfload.loadprofiles.ui.dialog.SettingsDialog.java

private boolean checkDirty() {
    if (dirty) {//ww w .j a va 2 s  .c  o  m
        switch (JOptionPane.showConfirmDialog(null, "Saves changes?")) {
        case JOptionPane.YES_OPTION:
            controller.setActiveSettings(Settings.of(operations, targets, clients));
            controller.saveActiveSettings();
            dirty = false;
            return true;
        case JOptionPane.NO_OPTION:
            dirty = false;
            return true;
        default:
            return false;
        }
    }
    return true;
}

From source file:serial.ChartFromSerial.java

private void pause_jBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pause_jBtnActionPerformed
    if ("Play".equals(pause_jBtn.getText())) {
        while (!chosenPort.openPort()) {
            if (JOptionPane.showConfirmDialog(rootPane,
                    "Error at " + portList_jCombo.getSelectedItem().toString() + "\nWould you like to refresh?",
                    "Trouble connecting to " + portList_jCombo.getSelectedItem().toString(),
                    JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.NO_OPTION) {
                buttonsOff();/*from w  w  w  .  j a v a 2 s  .c  o m*/
                return;
            } else {
                portNames = SerialPort.getCommPorts();
                if (portNames.length > 0) {
                    if (portNames.length >= 1) {
                        Object[] possibilities = new Object[portNames.length];
                        for (int i = 0; i < portNames.length; i++) {
                            possibilities[i] = portNames[i].getSystemPortName();
                        }
                        String s = (String) JOptionPane.showInputDialog(rootPane,
                                "Other ports are available.\nSelect one to continue on that port or cancel to disconnect.",
                                "Another port is available", JOptionPane.PLAIN_MESSAGE, null, possibilities,
                                null);
                        chosenPort.closePort();
                        if (s != null) {
                            chosenPort = SerialPort.getCommPort(s);
                            chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                            chosenPort.setBaudRate(
                                    Integer.parseInt(baudRate_jCombo.getSelectedItem().toString()));
                            softRefresh();
                            portList_jCombo.setSelectedItem(s);
                            if (chosenPort.openPort()) {
                                createSerialThread(chosenPort);
                                pause_jBtn.setText("Pause");
                                connect_jBtn.setEnabled(true);
                                return;
                            }
                        } else {
                            buttonsOff();
                            return;
                        }
                    } else {
                        if (JOptionPane.showConfirmDialog(rootPane,
                                portNames[0].getSystemPortName()
                                        + " is available. Would you like to use it instead?",
                                "Another port is available",
                                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                            chosenPort.closePort();
                            chosenPort = SerialPort.getCommPort(portNames[0].getSystemPortName());
                            chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                            chosenPort.setBaudRate(
                                    Integer.parseInt(baudRate_jCombo.getSelectedItem().toString()));
                            softRefresh();
                            portList_jCombo.setSelectedItem(portNames[0].getSystemPortName());
                            if (chosenPort.openPort()) {
                                createSerialThread(chosenPort);
                                pause_jBtn.setText("Pause");
                                connect_jBtn.setEnabled(true);
                                return;
                            }
                        } else {
                            buttonsOff();
                            return;
                        }
                    }
                } else {
                    JOptionPane.showMessageDialog(rootPane, "You are currently not connected to any devices.",
                            "No devices found", JOptionPane.INFORMATION_MESSAGE);
                    softRefresh();
                    buttonsOff();
                    return;
                }
            }

        }
        createSerialThread(chosenPort);
        pause_jBtn.setText("Pause");
    } else {
        chosenPort.closePort();
        pause_jBtn.setText("Play");
    }
}

From source file:components.DialogDemo.java

/** Creates the panel shown by the second tab. */
private JPanel createFeatureDialogBox() {
    final int numButtons = 5;
    JRadioButton[] radioButtons = new JRadioButton[numButtons];
    final ButtonGroup group = new ButtonGroup();

    JButton showItButton = null;/*from   w  w  w  .j  a  v a 2s .  c  om*/

    final String pickOneCommand = "pickone";
    final String textEnteredCommand = "textfield";
    final String nonAutoCommand = "nonautooption";
    final String customOptionCommand = "customoption";
    final String nonModalCommand = "nonmodal";

    radioButtons[0] = new JRadioButton("Pick one of several choices");
    radioButtons[0].setActionCommand(pickOneCommand);

    radioButtons[1] = new JRadioButton("Enter some text");
    radioButtons[1].setActionCommand(textEnteredCommand);

    radioButtons[2] = new JRadioButton("Non-auto-closing dialog");
    radioButtons[2].setActionCommand(nonAutoCommand);

    radioButtons[3] = new JRadioButton("Input-validating dialog " + "(with custom message area)");
    radioButtons[3].setActionCommand(customOptionCommand);

    radioButtons[4] = new JRadioButton("Non-modal dialog");
    radioButtons[4].setActionCommand(nonModalCommand);

    for (int i = 0; i < numButtons; i++) {
        group.add(radioButtons[i]);
    }
    radioButtons[0].setSelected(true);

    showItButton = new JButton("Show it!");
    showItButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String command = group.getSelection().getActionCommand();

            //pick one of many
            if (command == pickOneCommand) {
                Object[] possibilities = { "ham", "spam", "yam" };
                String s = (String) JOptionPane.showInputDialog(frame,
                        "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE, icon, possibilities, "ham");

                //If a string was returned, say so.
                if ((s != null) && (s.length() > 0)) {
                    setLabel("Green eggs and... " + s + "!");
                    return;
                }

                //If you're here, the return value was null/empty.
                setLabel("Come on, finish the sentence!");

                //text input
            } else if (command == textEnteredCommand) {
                String s = (String) JOptionPane.showInputDialog(frame,
                        "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE, icon, null, "ham");

                //If a string was returned, say so.
                if ((s != null) && (s.length() > 0)) {
                    setLabel("Green eggs and... " + s + "!");
                    return;
                }

                //If you're here, the return value was null/empty.
                setLabel("Come on, finish the sentence!");

                //non-auto-closing dialog
            } else if (command == nonAutoCommand) {
                final JOptionPane optionPane = new JOptionPane(
                        "The only way to close this dialog is by\n" + "pressing one of the following buttons.\n"
                                + "Do you understand?",
                        JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);

                //You can't use pane.createDialog() because that
                //method sets up the JDialog with a property change
                //listener that automatically closes the window
                //when a button is clicked.
                final JDialog dialog = new JDialog(frame, "Click a button", true);
                dialog.setContentPane(optionPane);
                dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                dialog.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent we) {
                        setLabel("Thwarted user attempt to close window.");
                    }
                });
                optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent e) {
                        String prop = e.getPropertyName();

                        if (dialog.isVisible() && (e.getSource() == optionPane)
                                && (JOptionPane.VALUE_PROPERTY.equals(prop))) {
                            //If you were going to check something
                            //before closing the window, you'd do
                            //it here.
                            dialog.setVisible(false);
                        }
                    }
                });
                dialog.pack();
                dialog.setLocationRelativeTo(frame);
                dialog.setVisible(true);

                int value = ((Integer) optionPane.getValue()).intValue();
                if (value == JOptionPane.YES_OPTION) {
                    setLabel("Good.");
                } else if (value == JOptionPane.NO_OPTION) {
                    setLabel("Try using the window decorations " + "to close the non-auto-closing dialog. "
                            + "You can't!");
                } else {
                    setLabel("Window unavoidably closed (ESC?).");
                }

                //non-auto-closing dialog with custom message area
                //NOTE: if you don't intend to check the input,
                //then just use showInputDialog instead.
            } else if (command == customOptionCommand) {
                customDialog.setLocationRelativeTo(frame);
                customDialog.setVisible(true);

                String s = customDialog.getValidatedText();
                if (s != null) {
                    //The text is valid.
                    setLabel("Congratulations!  " + "You entered \"" + s + "\".");
                }

                //non-modal dialog
            } else if (command == nonModalCommand) {
                //Create the dialog.
                final JDialog dialog = new JDialog(frame, "A Non-Modal Dialog");

                //Add contents to it. It must have a close button,
                //since some L&Fs (notably Java/Metal) don't provide one
                //in the window decorations for dialogs.
                JLabel label = new JLabel("<html><p align=center>" + "This is a non-modal dialog.<br>"
                        + "You can have one or more of these up<br>" + "and still use the main window.");
                label.setHorizontalAlignment(JLabel.CENTER);
                Font font = label.getFont();
                label.setFont(label.getFont().deriveFont(font.PLAIN, 14.0f));

                JButton closeButton = new JButton("Close");
                closeButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        dialog.setVisible(false);
                        dialog.dispose();
                    }
                });
                JPanel closePanel = new JPanel();
                closePanel.setLayout(new BoxLayout(closePanel, BoxLayout.LINE_AXIS));
                closePanel.add(Box.createHorizontalGlue());
                closePanel.add(closeButton);
                closePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5));

                JPanel contentPane = new JPanel(new BorderLayout());
                contentPane.add(label, BorderLayout.CENTER);
                contentPane.add(closePanel, BorderLayout.PAGE_END);
                contentPane.setOpaque(true);
                dialog.setContentPane(contentPane);

                //Show it.
                dialog.setSize(new Dimension(300, 150));
                dialog.setLocationRelativeTo(frame);
                dialog.setVisible(true);
            }
        }
    });

    return createPane(moreDialogDesc + ":", radioButtons, showItButton);
}

From source file:livecanvas.mesheditor.MeshEditor.java

private void save(File file) {
    if (!canSave()) {
        return;/*from w w  w. ja  v  a2  s .  c o  m*/
    }
    if (file == null) {
        FileDialog fd = new FileDialog(JOptionPane.getFrameForComponent(MeshEditor.this), "Save");
        fd.setVisible(true);
        String file_str = fd.getFile();
        if (file_str == null) {
            return;
        }
        file = new File(fd.getDirectory() + "/" + file_str);
    }
    try {
        Layer rootLayer = layersView.getRootLayer();
        for (Layer l : rootLayer.getSubLayersRecursively()) {
            Path path = l.getPath();
            if (path.isFinalized()) {
                Mesh mesh = path.getMesh();
                if (mesh.getControlPointsCount() < 2) {
                    String msg = "At least one mesh has less than 2 control points.\n"
                            + "You may not be able to use it for animation. Do you\n"
                            + "still want to continue?";
                    if (JOptionPane.showConfirmDialog(this, msg, "Warning", JOptionPane.YES_NO_OPTION,
                            JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
                        return;
                    } else {
                        break;
                    }
                }
            }
        }
        PrintWriter out = new PrintWriter(new FileOutputStream(file));
        JSONObject doc = new JSONObject();
        doc.put("rootLayer", rootLayer.toJSON());
        doc.put("canvas", canvas.toJSON());
        doc.write(out);
        out.close();
    } catch (Exception e1) {
        e1.printStackTrace();
        String msg = "An error occurred while trying to load.";
        JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(MeshEditor.this), msg, "Error",
                JOptionPane.ERROR_MESSAGE);
    }
    repaint();
}

From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterEditorDlg.java

/**
 * //from  ww w. j av a 2s.co  m
 */
protected void checkForChanges() {
    if (fieldHasChanged) {
        Object[] options = { getResourceString("SAVE"), //$NON-NLS-1$ 
                getResourceString("DISCARD") }; //$NON-NLS-1$
        int retVal = JOptionPane.showOptionDialog(null, getResourceString("FFE_SAVE_CHG"), //$NON-NLS-1$
                getResourceString("SaveChangesTitle"), JOptionPane.YES_NO_CANCEL_OPTION, //$NON-NLS-1$
                JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        if (retVal == JOptionPane.YES_OPTION) {
            fieldsPanel.getEditBtn().doClick();
        }
    }
}

From source file:com.alvermont.terraj.stargen.ui.SystemFrame.java

private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_saveMenuItemActionPerformed
{//GEN-HEADEREND:event_saveMenuItemActionPerformed

    final int choice = this.pngChooser.showSaveDialog(this);

    try {/*from  w ww. ja v a  2 s .c  o m*/
        if (choice == JFileChooser.APPROVE_OPTION) {
            if (!this.pngChooser.getSelectedFile().isFile() || (JOptionPane.showConfirmDialog(this,
                    "This file already exists. Do you want to\n" + "overwrite it?", "Replace File?",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)) {
                List<BufferedImage> images = UIUtils.getPlanetImages(this.planets);

                BufferedImage collage = UIUtils.combineImagesHorizontal(images);

                final File target = FileUtils.addExtension(this.pngChooser.getSelectedFile(), ".png");

                ImageIO.write(collage, PNGFileFilter.getFormatName(target), target);
            }
        }
    } catch (IOException ioe) {
        log.error("Error writing image file", ioe);

        JOptionPane.showMessageDialog(this, "Error: " + ioe.getMessage() + "\nCheck log file for full details",
                "Error Saving", JOptionPane.ERROR_MESSAGE);
    }

}

From source file:com.net2plan.gui.tools.GUINetworkDesign.java

private void resetButton() {
    try {/*  www .  ja va2  s .c o m*/
        final int result = JOptionPane.showConfirmDialog(null,
                "Are you sure you want to reset? This will remove all unsaved data", "Reset",
                JOptionPane.YES_NO_OPTION);
        if (result != JOptionPane.YES_OPTION)
            return;

        if (inOnlineSimulationMode()) {
            switch (onlineSimulationPane.getSimKernel().getSimCore().getSimulationState()) {
            case NOT_STARTED:
            case STOPPED:
                break;
            default:
                onlineSimulationPane.getSimKernel().getSimCore().setSimulationState(SimState.STOPPED);
                break;
            }
            onlineSimulationPane.getSimKernel().reset();
            setCurrentNetPlanDoNotUpdateVisualization(onlineSimulationPane.getSimKernel().getCurrentNetPlan());
        } else {
            setCurrentNetPlanDoNotUpdateVisualization(new NetPlan());
            //algorithmSelector.reset();
            executionPane.reset();
        }
        //            reportSelector.reset();
        //            reportContainer.removeAll();
    } catch (Throwable ex) {
        ErrorHandling.addErrorOrException(ex, GUINetworkDesign.class);
        ErrorHandling.showErrorDialog("Unable to reset");
    }
    Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = VisualizationState
            .generateCanvasDefaultVisualizationLayerInfo(getDesign());
    vs.setCanvasLayerVisibilityAndOrder(getDesign(), res.getFirst(), res.getSecond());
    updateVisualizationAfterNewTopology();
    undoRedoManager.addNetPlanChange();
}