Example usage for javax.swing JOptionPane ERROR_MESSAGE

List of usage examples for javax.swing JOptionPane ERROR_MESSAGE

Introduction

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

Prototype

int ERROR_MESSAGE

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

Click Source Link

Document

Used for error messages.

Usage

From source file:com.jostrobin.battleships.controller.GameController.java

@Override
public void notify(Command command) {
    switch (command.getCommand()) {
    case Command.ATTACK_RESULT:
        if (command.getAttackResult() != AttackResult.INVALID) {
            gameFrame.hitCell(command);/*from w w w. j  av a2s. c om*/

            AttackResult result = command.getAttackResult();

            // if a ship has been destroyed, add it to the game field
            if (result == AttackResult.SHIP_DESTROYED || result == AttackResult.PLAYER_DESTROYED) {
                gameFrame.addShip(command.getAttackedClient(), command.getShip());
            }
            playSound(result);
            checkGameUpdate(command);
            gameFrame.changeCurrentPlayer(command.getClientId());
        }
        break;
    case Command.CLOSE_GAME:
        // the game has been aborted, go back to main screen
        JOptionPane.showMessageDialog(gameFrame, "The game has been aborted by another player.", "Error",
                JOptionPane.ERROR_MESSAGE);
        applicationController.showGameSelection();
        gameFrame.reset();
        gameModel.setPlayers(null);
        break;
    }
}

From source file:com.emr.utilities.SQLiteGetProcesses.java

@Override
protected void done() {
    if (!"".equals(error_msg)) {
        JOptionPane.showMessageDialog(null, "Could not fetch saved procedures. Error details: " + error_msg,
                "Failed", JOptionPane.ERROR_MESSAGE);
    }//from w  ww.j ava 2s.co  m
}

From source file:LookAndFeelPrefs.java

/**
 * Create a menu of radio buttons listing the available Look and Feels. When
 * the user selects one, change the component hierarchy under frame to the new
 * LAF, and store the new selection as the current preference for the package
 * containing class c.// w  w w  . ja  v  a  2  s  . c o m
 */
public static JMenu createLookAndFeelMenu(final Class prefsClass, final ActionListener listener) {
    // Create the menu
    final JMenu plafmenu = new JMenu("Look and Feel");

    // Create an object used for radio button mutual exclusion
    ButtonGroup radiogroup = new ButtonGroup();

    // Look up the available look and feels
    UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();

    // Find out which one is currently used
    String currentLAFName = UIManager.getLookAndFeel().getClass().getName();

    // Loop through the plafs, and add a menu item for each one
    for (int i = 0; i < plafs.length; i++) {
        String plafName = plafs[i].getName();
        final String plafClassName = plafs[i].getClassName();

        // Create the menu item
        final JMenuItem item = plafmenu.add(new JRadioButtonMenuItem(plafName));
        item.setSelected(plafClassName.equals(currentLAFName));

        // Tell the menu item what to do when it is selected
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                // Set the new look and feel
                try {
                    UIManager.setLookAndFeel(plafClassName);
                } catch (UnsupportedLookAndFeelException e) {
                    // Sometimes a Look-and-Feel is installed but not
                    // supported, as in the Windows LaF on Linux platforms.
                    JOptionPane.showMessageDialog(plafmenu,
                            "The selected Look-and-Feel is " + "not supported on this platform.",
                            "Unsupported Look And Feel", JOptionPane.ERROR_MESSAGE);
                    item.setEnabled(false);
                } catch (Exception e) { // ClassNotFound or Instantiation
                    item.setEnabled(false); // shouldn't happen
                }

                // Make the selection persistent by storing it in prefs.
                Preferences p = Preferences.userNodeForPackage(prefsClass);
                p.put(PREF_NAME, plafClassName);

                // Invoke the supplied action listener so the calling
                // application can update its components to the new LAF
                // Reuse the event that was passed here.
                listener.actionPerformed(event);
            }
        });

        // Only allow one menu item to be selected at once
        radiogroup.add(item);
    }

    return plafmenu;
}

From source file:edu.smc.mediacommons.panels.PasswordPanel.java

public PasswordPanel() {
    setLayout(null);/*from  w w w  . j a v  a  2  s  . c  om*/

    add(Utils.createLabel("Enter a Password to Test", 60, 30, 200, 20, null));

    final JButton test = Utils.createButton("Test", 260, 50, 100, 20, null);
    add(test);

    final JPasswordField fieldPassword = new JPasswordField(32);
    fieldPassword.setBounds(60, 50, 200, 20);
    add(fieldPassword);

    final PieDataset dataset = createSampleDataset(33, 33, 33);
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(300, 300));
    chartPanel.setBounds(45, 80, 340, 250);

    add(chartPanel);

    test.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String password = new String(fieldPassword.getPassword());

            if (password.isEmpty() || password == null) {
                JOptionPane.showMessageDialog(getParent(), "Warning! The input was blank!", "Invalid Input",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                int letterCount = 0, numberCount = 0, specialCount = 0, total = password.length();

                for (char c : password.toCharArray()) {
                    if (Character.isLetter(c)) {
                        letterCount++;
                    } else if (Character.isDigit(c)) {
                        numberCount++;
                    } else {
                        specialCount++;
                    }
                }

                long totalCombinations = 0;
                double percentLetters = 0;
                double percentNumbers = 0;
                double percentCharacters = 0;

                if (letterCount > 0) {
                    totalCombinations += (factorial(26) / factorial(26 - letterCount));
                    percentLetters = (letterCount + 0.0 / total);
                }

                if (numberCount > 0) {
                    totalCombinations += (factorial(10) / factorial(10 - numberCount));
                    percentNumbers = (numberCount + 0.0 / total);
                }

                if (specialCount > 0) {
                    totalCombinations += (factorial(40) / factorial(40 - specialCount));
                    percentCharacters = (specialCount + 0.0 / total);
                }

                PieDataset dataset = createSampleDataset(percentLetters, percentNumbers, percentCharacters);
                JFreeChart chart = createChart(dataset);
                chartPanel.setChart(chart);

                JOptionPane.showMessageDialog(getParent(),
                        "Total Combinations: " + totalCombinations + "\nAssuming Rate Limited, Single: "
                                + (totalCombinations / 1000) + " seconds" + "\n\nBreakdown:\nLetters: "
                                + percentLetters + "%\nNumbers: " + percentNumbers + "%\nCharacters: "
                                + percentCharacters + "%");
            }
        }
    });

    setVisible(true);
}

From source file:it.imtech.configuration.StartWizard.java

/**
 * Creates a new wizard with active card (Select Language/Server)
 *//*from  w w w .j a v a2 s. c  o  m*/
public StartWizard() {
    Globals.setGlobalVariables();
    ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader);

    if (!checkAppDataFiles()) {
        JOptionPane.showMessageDialog(null, Utility.getBundleString("copy_appdata", bundle),
                Utility.getBundleString("copy_appdata_title", bundle), JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }

    DOMConfigurator.configure(Globals.LOG4J);
    logger = Logger.getLogger(StartWizard.class);
    logger.info("Starting Application Phaidra Importer");

    mainFrame = new JFrame();

    if (Utility.internetConnectionAvailable()) {
        Globals.ONLINE = true;
    }

    it.imtech.utility.Utility.cleanUndoDir();

    XMLConfiguration internalConf = setConfiguration();
    logger.info("Configuration path estabilished");

    XMLConfiguration config = setConfigurationPaths(internalConf, bundle);

    headerPanel = new HeaderPanel();
    footerPanel = new FooterPanel();

    JButton nextButton = (JButton) footerPanel.getComponentByName("next_button");
    JButton prevButton = (JButton) footerPanel.getComponentByName("prev_button");

    nextButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (getCurrentCard() instanceof ChooseServer) {
                ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                        Globals.loader);

                try {
                    mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                    Server selected = chooseServer.getSelectedServer();
                    logger.info("Selected Server = " + selected.getServername());
                    SelectedServer.getInstance(null).makeEmpty();
                    SelectedServer.getInstance(selected);

                    if (Globals.ONLINE) {
                        logger.info("Testing server connection...");
                        ChooseServer.testServerConnection(SelectedServer.getInstance(null).getBaseUrl());
                    }
                    chooseFolder.updateLanguage();

                    MetaUtility.getInstance().preInitializeData();
                    logger.info("Preinitialization done (Vocabulary and Languages");

                    c1.next(cardsPanel);
                    mainFrame.setCursor(null);
                } catch (Exception ex) {
                    logger.error(ex.getMessage());
                    JOptionPane.showMessageDialog(new Frame(),
                            Utility.getBundleString("preinitializemetadataex", bundle));
                }
            } else if (getCurrentCard() instanceof ChooseFolder) {
                mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                boolean error = chooseFolder.checkFolderSelectionValidity();

                if (error == false) {
                    BookImporter x = BookImporter.getInstance();
                    mainFrame.setCursor(null);
                    mainFrame.setVisible(false);
                }
            }
        }
    });

    prevButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (getCurrentCard() instanceof ChooseServer) {
                ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                        Globals.loader);
                String title = Utility.getBundleString("dialog_1_title", bundle);
                String text = Utility.getBundleString("dialog_1", bundle);

                ConfirmDialog confirm = new ConfirmDialog(mainFrame, true, title, text,
                        Utility.getBundleString("confirm", bundle), Utility.getBundleString("back", bundle));

                confirm.setVisible(true);
                boolean close = confirm.getChoice();
                confirm.dispose();

                if (close == true) {
                    mainFrame.dispose();
                }
            } else {
                c1.previous(cardsPanel);
            }
        }
    });

    cardsPanel = new JPanel(new CardLayout());
    cardsPanel.setBackground(Color.WHITE);

    chooseServer = new ChooseServer(config);
    chooseFolder = new ChooseFolder();

    cardsPanel.add(chooseServer, "1");
    cardsPanel.add(chooseFolder, "2");

    cardsPanel.setLayout(c1);
    c1.show(cardsPanel, "1");

    //Main Panel style
    mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(BorderLayout.NORTH, headerPanel);
    mainPanel.add(BorderLayout.CENTER, cardsPanel);
    mainPanel.add(BorderLayout.PAGE_END, footerPanel);
    mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    mainFrame.addWindowListener(new java.awt.event.WindowAdapter() {
        @Override
        public void windowClosing(java.awt.event.WindowEvent windowEvent) {
            ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                    Globals.loader);
            String title = Utility.getBundleString("dialog_1_title", bundle);
            String text = Utility.getBundleString("dialog_1", bundle);

            ConfirmDialog confirm = new ConfirmDialog(mainFrame, true, title, text,
                    Utility.getBundleString("confirm", bundle), Utility.getBundleString("back", bundle));

            confirm.setVisible(true);
            boolean close = confirm.getChoice();
            confirm.dispose();

            if (close == true) {
                mainFrame.dispose();
            }
        }
    });

    //Add Style 
    mainFrame.getContentPane().setBackground(Color.white);
    mainFrame.getContentPane().setLayout(new BorderLayout());
    mainFrame.getContentPane().setPreferredSize(new Dimension(640, 400));
    mainFrame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    mainFrame.pack();

    //Center frame in the screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (dim.width - mainFrame.getSize().width) / 2;
    int y = (dim.height - mainFrame.getSize().height) / 2;
    mainFrame.setLocation(x, y);

    mainFrame.setVisible(true);
}

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

private void programButtonActionPerformed(ActionEvent e) {
    if (ReaderContext.isUsbConnected()) {
        if (ReaderContext.isUsbReading()) {
            ReaderContext.stopReading();
            programButton.setText("Iniciar la programacin");
        } else {/*  w  w w .jav  a2 s  . c o  m*/
            try {
                if (lockCheckbox.isSelected() && (!validatePasswords())) {
                    JOptionPane.showMessageDialog(this,
                            "Se deben establecer contraseas de 8 caracteres [0-9],[a-f].", "Iniciar lectura",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                try {
                    Integer.valueOf(nextChipnumberTextField.getText());
                    ReaderContext.startReading();
                    programButton.setText("Detener la programacin");
                } catch (NumberFormatException e1) {
                    JOptionPane.showMessageDialog(this, "Se debe establecer un valor para el siguiente chip.",
                            "Iniciar lectura", JOptionPane.ERROR_MESSAGE);

                }
            } catch (ReaderException e1) {
                JOptionPane.showMessageDialog(this, "No se pudo iniciar la lectura.", "Iniciar lectura",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}

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

public List<String> getAliases() throws KeyStoreException, NoSuchAlgorithmException, CertificateException,
        IOException, UnrecoverableEntryException {
    List<String> aliases = new LinkedList<String>();
    try {//from  ww  w  .  j a  v a 2  s  .  c om
        this.keyStore = KeyStore.getInstance("PKCS11", this.pkcs11Provider);
    } catch (KeyStoreException e) {
        JOptionPane.showMessageDialog(null, "No keystore present: " + e.getMessage(), "PKCS#11 error",
                JOptionPane.ERROR_MESSAGE);
        throw e;
    }
    LoadStoreParameter loadStoreParameter = new Pkcs11LoadStoreParameter();
    try {
        this.keyStore.load(loadStoreParameter);
    } catch (IOException e) {
        LOG.debug("I/O error: " + e.getMessage(), e);
        Throwable cause = e.getCause();
        if (null != cause) {
            if (cause instanceof FailedLoginException) {
                JOptionPane.showMessageDialog(null, "PIN incorrect", "Login failed", JOptionPane.ERROR_MESSAGE);
            }
        }
        return aliases;
    }
    Enumeration<String> aliasesEnum = this.keyStore.aliases();
    while (aliasesEnum.hasMoreElements()) {
        String alias = aliasesEnum.nextElement();
        LOG.debug("keystore alias: " + alias);
        if (false == this.keyStore.isKeyEntry(alias)) {
            continue;
        }
        aliases.add(alias);
    }
    return aliases;
}

From source file:eu.apenet.dpt.standalone.gui.XsltAdderActionListener.java

public void actionPerformed(ActionEvent e) {
    JFileChooser xsltChooser = new JFileChooser();
    xsltChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (xsltChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        File file = xsltChooser.getSelectedFile();
        if (isXSLT(file)) {
            if (saveXslt(file)) {
                JRadioButton newButton = new JRadioButton(file.getName());
                newButton.addActionListener(new XsltSelectorListener(dataPreparationToolGUI));
                dataPreparationToolGUI.getGroupXslt().add(newButton);
                dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsltPanel(newButton);
                dataPreparationToolGUI.getAPEPanel().getApeTabbedPane()
                        .addToXsltPanel(Box.createRigidArea(new Dimension(0, 10)));
                JOptionPane.showMessageDialog(parent, labels.getString("xsltSaved") + ".",
                        labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon);
            } else {
                JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".",
                        labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon);
            }//from  ww  w  . j  a v  a 2  s  . c om
        } else {
            JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".",
                    labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon);
        }
    }
}

From source file:au.org.ala.delta.intkey.ui.RealInputDialog.java

@Override
void handleBtnOKClicked() {
    String inputTxt = _txtInput.getText();
    if (inputTxt.length() > 0) {
        try {/*from  w  w  w.  j a v a2 s.c  o m*/
            _inputData = ParsingUtils.parseRealCharacterValue(inputTxt);
            setVisible(false);
        } catch (IllegalArgumentException ex) {
            JOptionPane.showMessageDialog(this, validationErrorMessage, validationErrorTitle,
                    JOptionPane.ERROR_MESSAGE);
        }
    } else {
        // return a float range with negative infinity. This represents
        // "no values selected".
        _inputData = new FloatRange(Float.NEGATIVE_INFINITY);
        setVisible(false);
    }
}

From source file:by.dak.cutting.permision.PermissionManager.java

public void login() {
    JXLoginPane pane = new JXLoginPane(loginService);
    JXLoginPane.Status status = JXLoginPane.showLoginDialog(CuttingApp.getApplication().getMainFrame(), pane);
    if (status == JXLoginPane.Status.SUCCEEDED) {
        Runnable runnable = new Runnable() {
            public void run() {
                NewDayManager newDayManager = new NewDayManager();
                Dailysheet dailysheet = newDayManager.checkDailysheet();
                if (dailysheet == null) {
                    Application.getInstance().exit();
                }//from  w ww .jav a 2  s .  c  o m
                if (!newDayManager.checkCurrency(dailysheet)) {
                    JOptionPane.showMessageDialog(
                            ((SingleFrameApplication) Application.getInstance()).getMainFrame(),
                            resourceMap.getString("permission.title.currency.empty"),
                            resourceMap.getString("permission.message.currency.empty"),
                            JOptionPane.ERROR_MESSAGE);
                    CuttingApp.getApplication().exit();
                }

            }
        };
        SwingUtilities.invokeLater(runnable);
    } else {
        Application.getInstance().exit();
    }
}