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.GoEuro.paseOperation.ParseObject.java

public static List<City> parseArray(String jsonArray) {

    List<City> cities = new ArrayList<>();
    try {/*from w w  w.  ja  va  2 s. c  o m*/
        JSONArray jsonarray = new JSONArray(jsonArray);
        for (int i = 0; i < jsonarray.length(); i++) {
            JSONObject jsonobject = jsonarray.getJSONObject(i);
            City city = parseJson(jsonobject.toString());
            cities.add(city);
            System.out.println(city.toString());
        }
    } catch (JSONException ex) {
        System.err.println("ERROR: " + ex.getMessage());
        JOptionPane.showMessageDialog(null, "Error parsing Json Array",
                "Error parsing Json Array: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
    }
    return cities;
}

From source file:Main.java

public Main() {
    options.add(createOptionPane("Plain Message", JOptionPane.PLAIN_MESSAGE));
    options.add(createOptionPane("Error Message", JOptionPane.ERROR_MESSAGE));
    options.add(createOptionPane("Information Message", JOptionPane.INFORMATION_MESSAGE));
    options.add(createOptionPane("Warning Message", JOptionPane.WARNING_MESSAGE));
    options.add(createOptionPane("Want to do something?", JOptionPane.QUESTION_MESSAGE));
    items = new Object[] { "First", "Second", "Third" };
    JComboBox choiceCombo = new JComboBox(items);
    options.add(new JOptionPane(choiceCombo, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION),
            "Question Message");
    JFrame frame = new JFrame("JOptionPane'Options");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(options, BorderLayout.CENTER);
    frame.pack();//from  w  w w  .  j  a va  2 s. c om
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Browse to a folder.//from  w ww  .  j a  v  a2  s. c  o m
 * 
 * @param file the path
 * @param component the component
 */
public static void browseDir(File file, Component component) {
    try {
        Desktop.getDesktop().browse(new URL("file://" + file.getAbsolutePath()).toURI());
    } catch (IOException e) {
        JOptionPane.showMessageDialog(component,
                "Unable to open '" + file.getAbsolutePath() + "'. Maybe it doesn't exist?", "Open failed",
                JOptionPane.ERROR_MESSAGE);
    } catch (URISyntaxException e) {
    }
}

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

public static void solicitarLogin() {
    String usuario;//w  w  w  .j a v  a  2s  . co  m
    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:de.erdesignerng.visual.MessagesHelper.java

public static void displayErrorMessage(Component aParent, String aMessage, String aErrorText) {
    JOptionPane.showMessageDialog(aParent, StringEscapeUtils.unescapeJava(aMessage), aErrorText,
            JOptionPane.ERROR_MESSAGE);
}

From source file:MainClass.java

public MainClass(String filename) {
    ProgressMonitorInputStream monitor;
    try {//from   www  .  j  ava  2 s  . c  o  m
        monitor = new ProgressMonitorInputStream(null, "Loading " + filename, new FileInputStream(filename));
        while (monitor.available() > 0) {
            byte[] data = new byte[38];
            monitor.read(data);
            System.out.write(data);
        }
    } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(null, "Unable to find file: " + filename, "Error",
                JOptionPane.ERROR_MESSAGE);
    } catch (IOException e) {
        ;
    }
}

From source file:core.Utility.java

public static void ShowError(String title, String message) {
    JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE, null);
}

From source file:Main.java

/**
 * visualizzazione errori HTML//from w  ww .j a v a 2  s .  com
 *
 * @param frame frame di provenienza (di solito e' <code>this</code>).
 * @param task task di provenienza dell'errore (di solito e'
 * <code>TASK_NAME</code>).
 * @param mess messaggio da visualizzare
 */
public static void dispErrore(JFrame frame, String task, String mess) {
    //
    JOptionPane.showMessageDialog(frame, formattaHTML(mess), ERR_TITLE, JOptionPane.ERROR_MESSAGE);
}

From source file:Main.java

/**
 * visualizzazione errori HTML//from   w w  w  . ja v a 2s.  c o  m
 *
 * @param iframe internal frame di provenienza (di solito e'
 * <code>this</code>).
 * @param task task di provenienza dell'errore (di solito e'
 * <code>TASK_NAME</code>).
 * @param mess messaggio da visualizzare
 */
public static void dispInternalErrore(JInternalFrame iframe, String task, String mess) {
    //
    JOptionPane.showInternalMessageDialog(iframe, formattaHTML(mess), ERR_TITLE, JOptionPane.ERROR_MESSAGE);
}

From source file:au.com.jwatmuff.eventmanager.Main.java

/**
 * Main method.//  w  w  w  . j  av  a 2 s  .c  o  m
 */
public static void main(String args[]) {
    LogUtils.setupUncaughtExceptionHandler();

    /* Set timeout for RMI connections - TODO: move to external file */
    System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "2000");
    updateRmiHostName();

    /*
     * Set up menu bar for Mac
     */
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Event Manager");

    /*
     * Set look and feel to 'system' style
     */
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        log.info("Failed to set system look and feel");
    }

    /*
     * Set workingDir to a writable folder for storing competitions, settings etc.
     */
    String applicationData = System.getenv("APPDATA");
    if (applicationData != null) {
        workingDir = new File(applicationData, "EventManager");
        if (workingDir.exists() || workingDir.mkdirs()) {
            // redirect logging to writable folder
            LogUtils.reconfigureFileAppenders("log4j.properties", workingDir);
        } else {
            workingDir = new File(".");
        }
    }

    // log version for debugging
    log.info("Running version: " + VISIBLE_VERSION + " (Internal: " + VERSION + ")");

    /*
     * Copy license if necessary
     */
    File license1 = new File("license.lic");
    File license2 = new File(workingDir, "license.lic");
    if (license1.exists() && !license2.exists()) {
        try {
            FileUtils.copyFile(license1, license2);
        } catch (IOException e) {
            log.warn("Failed to copy license from " + license1 + " to " + license2, e);
        }
    }
    if (license1.exists() && license2.exists()) {
        if (license1.lastModified() > license2.lastModified()) {
            try {
                FileUtils.copyFile(license1, license2);
            } catch (IOException e) {
                log.warn("Failed to copy license from " + license1 + " to " + license2, e);
            }
        }
    }

    /*
     * Check if run lock exists, if so ask user if it is ok to continue
     */
    if (!obtainRunLock(false)) {
        int response = JOptionPane.showConfirmDialog(null,
                "Unable to obtain run-lock.\nPlease ensure that no other instances of EventManager are running before continuing.\nDo you wish to continue?",
                "Run-lock detected", JOptionPane.YES_NO_OPTION);
        if (response == JOptionPane.YES_OPTION)
            obtainRunLock(true);
        else
            System.exit(0);
    }

    try {
        LoadWindow loadWindow = new LoadWindow();
        loadWindow.setVisible(true);

        loadWindow.addMessage("Reading settings..");

        /*
         * Read properties from file
         */
        final Properties props = new Properties();
        try {
            Properties defaultProps = PropertiesLoaderUtils
                    .loadProperties(new ClassPathResource("eventmanager.properties"));
            props.putAll(defaultProps);
        } catch (IOException ex) {
            log.error(ex);
        }

        props.putAll(System.getProperties());

        File databaseStore = new File(workingDir, "comps");
        int rmiPort = Integer.parseInt(props.getProperty("eventmanager.rmi.port"));

        loadWindow.addMessage("Loading Peer Manager..");
        log.info("Loading Peer Manager");

        ManualDiscoveryService manualDiscoveryService = new ManualDiscoveryService();
        JmDNSRMIPeerManager peerManager = new JmDNSRMIPeerManager(rmiPort, new File(workingDir, "peerid.dat"));
        peerManager.addDiscoveryService(manualDiscoveryService);

        monitorNetworkInterfaceChanges(peerManager);

        loadWindow.addMessage("Loading Database Manager..");
        log.info("Loading Database Manager");

        DatabaseManager databaseManager = new SQLiteDatabaseManager(databaseStore, peerManager);
        LicenseManager licenseManager = new LicenseManager(workingDir);

        loadWindow.addMessage("Loading Load Competition Dialog..");
        log.info("Loading Load Competition Dialog");

        LoadCompetitionWindow loadCompetitionWindow = new LoadCompetitionWindow(databaseManager, licenseManager,
                peerManager);
        loadCompetitionWindow.setTitle(WINDOW_TITLE);

        loadWindow.dispose();
        log.info("Starting Load Competition Dialog");

        while (true) {
            // reset permission checker to use our license
            licenseManager.updatePermissionChecker();

            GUIUtils.runModalJFrame(loadCompetitionWindow);

            if (loadCompetitionWindow.getSuccess()) {
                DatabaseInfo info = loadCompetitionWindow.getSelectedDatabaseInfo();

                if (!databaseManager.checkLock(info.id)) {
                    String message = "EventManager did not shut down correctly the last time this competition was open. To avoid potential data corruption, you are advised to take the following steps:\n"
                            + "1) Do NOT open this competition\n" + "2) Create a backup of this competition\n"
                            + "3) Delete the competition from this computer\n"
                            + "4) If possible, reload this competition from another computer on the network\n"
                            + "5) Alternatively, you may manually load the backup onto all computers on the network, ensuring the 'Preserve competition ID' option is checked.";
                    String title = "WARNING: Potential Data Corruption Detected";

                    int status = JOptionPane.showOptionDialog(null, message, title, JOptionPane.YES_NO_OPTION,
                            JOptionPane.ERROR_MESSAGE, null,
                            new Object[] { "Cancel (recommended)", "Open anyway" }, "Cancel (recommended)");

                    if (status == 0)
                        continue; // return to load competition window
                }

                SynchronizingWindow syncWindow = new SynchronizingWindow();
                syncWindow.setVisible(true);
                long t = System.nanoTime();
                DistributedDatabase database = databaseManager.activateDatabase(info.id, info.passwordHash);
                long dt = System.nanoTime() - t;
                log.debug(String.format("Initial sync in %dms",
                        TimeUnit.MILLISECONDS.convert(dt, TimeUnit.NANOSECONDS)));
                syncWindow.dispose();

                if (loadCompetitionWindow.isNewDatabase()) {
                    GregorianCalendar calendar = new GregorianCalendar();
                    Date today = calendar.getTime();
                    calendar.set(Calendar.MONTH, Calendar.DECEMBER);
                    calendar.set(Calendar.DAY_OF_MONTH, 31);
                    Date endOfYear = new java.sql.Date(calendar.getTimeInMillis());

                    CompetitionInfo ci = new CompetitionInfo();
                    ci.setName(info.name);
                    ci.setStartDate(today);
                    ci.setEndDate(today);
                    ci.setAgeThresholdDate(endOfYear);
                    //ci.setPasswordHash(info.passwordHash);
                    License license = licenseManager.getLicense();
                    if (license != null) {
                        ci.setLicenseName(license.getName());
                        ci.setLicenseType(license.getType().toString());
                        ci.setLicenseContact(license.getContactPhoneNumber());
                    }
                    database.add(ci);
                }

                // Set PermissionChecker to use database's license type
                String competitionLicenseType = database.get(CompetitionInfo.class, null).getLicenseType();
                PermissionChecker.setLicenseType(LicenseType.valueOf(competitionLicenseType));

                TransactionNotifier notifier = new TransactionNotifier();
                database.setListener(notifier);

                MainWindow mainWindow = new MainWindow();
                mainWindow.setDatabase(database);
                mainWindow.setNotifier(notifier);
                mainWindow.setPeerManager(peerManager);
                mainWindow.setLicenseManager(licenseManager);
                mainWindow.setManualDiscoveryService(manualDiscoveryService);
                mainWindow.setTitle(WINDOW_TITLE);
                mainWindow.afterPropertiesSet();

                TestUtil.setActivatedDatabase(database);

                // show main window (modally)
                GUIUtils.runModalJFrame(mainWindow);

                // shutdown procedures

                // System.exit();

                database.shutdown();
                databaseManager.deactivateDatabase(1500);

                if (mainWindow.getDeleteOnExit()) {
                    for (File file : info.localDirectory.listFiles())
                        if (!file.isDirectory())
                            file.delete();
                    info.localDirectory.deleteOnExit();
                }
            } else {
                // This can cause an RuntimeException - Peer is disconnected
                peerManager.stop();
                System.exit(0);
            }
        }
    } catch (Throwable e) {
        log.error("Error in main function", e);
        String message = e.getMessage();
        if (message == null)
            message = "";
        if (message.length() > 100)
            message = message.substring(0, 97) + "...";
        GUIUtils.displayError(null,
                "An unexpected error has occured.\n\n" + e.getClass().getSimpleName() + "\n" + message);
        System.exit(0);
    }
}