Example usage for javax.swing JOptionPane showMessageDialog

List of usage examples for javax.swing JOptionPane showMessageDialog

Introduction

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

Prototype

public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType)
        throws HeadlessException 

Source Link

Document

Brings up a dialog that displays a message using a default icon determined by the messageType parameter.

Usage

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

private void startReadingButtonActionPerformed(ActionEvent e) {
    if (ReaderContext.isUsbConnected()) {
        if (ReaderContext.isUsbReading()) {
            ReaderContext.stopReading();
            startReadingButton.setText("Iniciar la lectura");
        } else {//  w  w w .  j  a  v  a  2s. co m
            try {
                ReaderContext.startReading();
                startReadingButton.setText("Detener la lectura");
            } catch (ReaderException e1) {
                JOptionPane.showMessageDialog(this, "No se pudo iniciar la lectura.", "Iniciar lectura",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}

From source file:net.openbyte.gui.CreateProjectFrame.java

private void button1ActionPerformed(ActionEvent e) {
    if (!(Launch.nameToSolution.get(textField1.getText()) == null)) {
        JOptionPane.showMessageDialog(this, "Project has already been created.", "Error",
                JOptionPane.ERROR_MESSAGE);
        return;/*from w  w  w  .  j av  a  2s  .c  om*/
    }
    ModificationAPI modificationAPI = ModificationAPI.MINECRAFT_FORGE;
    String apiName = (String) comboBox1.getSelectedItem();
    if (apiName.equals("MCP")) {
        modificationAPI = ModificationAPI.MCP;
    }
    if (apiName.equals("Bukkit")) {
        modificationAPI = ModificationAPI.BUKKIT;
    }
    MinecraftVersion minecraftVersion = MinecraftVersion.BOUNTIFUL_UPDATE;
    if (((String) comboBox2.getSelectedItem()).equals("1.7.10")) {
        minecraftVersion = MinecraftVersion.THE_UPDATE_THAT_CHANGED_THE_WORLD;
    }
    if (modificationAPI == ModificationAPI.MCP) {
        minecraftVersion = MinecraftVersion.COMBAT_UPDATE;
        String version = (String) comboBox2.getSelectedItem();
        if (version.equals("1.8.9")) {
            minecraftVersion = MinecraftVersion.BOUNTIFUL_UPDATE;
        }
        if (version.equals("1.7.10")) {
            minecraftVersion = MinecraftVersion.THE_UPDATE_THAT_CHANGED_THE_WORLD;
        }
    }
    if (modificationAPI == ModificationAPI.BUKKIT) {
        minecraftVersion = MinecraftVersion.COMBAT_UPDATE;
    }
    this.version = minecraftVersion;
    this.api = modificationAPI;
    setVisible(false);
    //JOptionPane.showMessageDialog(this, "We're working on setting up the project. When we are ready, a window will show up.", "Working on project creation", JOptionPane.INFORMATION_MESSAGE);
    this.projectName = textField1.getText();
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            doOperations();
            return null;
        }
    };
    monitor.setMillisToPopup(0);
    monitor.setMillisToDecideToPopup(0);
    monitor.setProgress(1);
    worker.execute();
    if (monitor.isCanceled()) {
        projectFolder.delete();
        new File(Files.WORKSPACE_DIRECTORY, projectName + ".openproj").delete();
        return;
    }
}

From source file:com.emr.schemas.DestinationTables.java

/**
 * Creates a new DestinationTables form.
 * @param sourceQuery {@link String} SQL Query for getting the source data.
 * @param selected_columns {@link List} List containing the selected source columns
 * @param sourceTables {@link List} List containing the source tables
 * @param relations {@link String} Relationship between the source tables
 * @param emrConn {@link Connection} KenyaEMR Database Connection object
 *//*from w  w w  .j av a2s.c  om*/
public DestinationTables(String sourceQuery, List selected_columns, List sourceTables, String relations,
        Connection emrConn, TableRelationsForm parent) {
    fileManager = null;
    dbManager = null;
    mpiConn = null;

    this.parent = parent;
    this.sourceQuery = sourceQuery;
    this.selected_columns = selected_columns;
    this.sourceTables = sourceTables;
    this.relations = relations;
    this.emrConn = emrConn;

    listModel = new DefaultListModel<String>();
    initComponents();
    this.setClosable(true);

    SourceTablesListener listSelectionListener = new SourceTablesListener(new JTextArea(), listOfTables);

    destinationTablesList.setCellRenderer(new CheckboxListCellRenderer());
    destinationTablesList.addListSelectionListener(listSelectionListener);
    destinationTablesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    //Create KenyaEMR DB connection
    fileManager = new FileManager();
    String[] settings = fileManager.getConnectionSettings("mpi_database.properties", "mpi");
    if (settings == null) {
        //Connection settings not found
        //Open MPIConnectionForm
        JOptionPane.showMessageDialog(null,
                "Database Settings not found. Please set the connection settings for the database first.",
                "MPI Database settings", JOptionPane.ERROR_MESSAGE);

    } else {
        if (settings.length < 1) {
            //Open MPIConnectionForm
            JOptionPane.showMessageDialog(null,
                    "Database Settings not found. Please set the connection settings for the database first.",
                    "MPI Database settings", JOptionPane.ERROR_MESSAGE);

        } else {
            //Connection settings are ok
            //We establish a connection
            dbManager = new DatabaseManager(settings[0], settings[1], settings[3], settings[4], settings[5]);
            mpiConn = dbManager.getConnection();
            if (mpiConn == null) {
                JOptionPane.showMessageDialog(null, "Test Connection Failed", "Connection Test",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                //get emr schema
                getDatabaseMetaData();
            }
        }
    }
}

From source file:com.peter.javaautoupdater.JavaAutoUpdater.java

public static void run(String ftpHost, int ftpPort, String ftpUsername, String ftpPassword,
        boolean isLocalPassiveMode, boolean isRemotePassiveMode, String basePath, String softwareName,
        String args[]) {//from  w ww . j  a  v a2 s  . c om
    System.out.println("jarName=" + jarName);
    for (String arg : args) {
        if (arg.toLowerCase().trim().equals("-noautoupdate")) {
            return;
        }
    }
    JavaAutoUpdater.basePath = basePath;
    JavaAutoUpdater.softwareName = softwareName;
    JavaAutoUpdater.args = args;

    if (!jarName.endsWith(".jar") || jarName.startsWith("JavaAutoUpdater-")) {
        if (isDebug) {
            jarName = "test.jar";
        } else {
            return;
        }
    }
    JProgressBarDialog d = new JProgressBarDialog(new JFrame(), "Auto updater", true);

    d.progressBar.setIndeterminate(true);
    d.progressBar.setStringPainted(true);
    d.progressBar.setString("Updating");
    //      d.addCancelEventListener(this);
    Thread longRunningThread = new Thread() {
        public void run() {
            d.progressBar.setString("checking latest version");
            System.out.println("checking latest version");

            FTPClient ftp = new FTPClient();
            try {
                ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
                ftp.connect(ftpHost, ftpPort);
                int reply = ftp.getReplyCode();
                System.out.println("reply=" + reply + ", " + FTPReply.isPositiveCompletion(reply));
                if (!FTPReply.isPositiveCompletion(reply)) {
                    ftp.disconnect();
                    JOptionPane.showMessageDialog(null, "FTP server refused connection", "error",
                            JOptionPane.ERROR_MESSAGE);
                }
                d.progressBar.setString("connected to ftp");
                System.out.println("connected to ftp");
                boolean success = ftp.login(ftpUsername, ftpPassword);
                if (!success) {
                    ftp.disconnect();
                    JOptionPane.showMessageDialog(null, "FTP login fail, can't update software", "error",
                            JOptionPane.ERROR_MESSAGE);
                }
                if (isLocalPassiveMode) {
                    ftp.enterLocalPassiveMode();
                }
                if (isRemotePassiveMode) {
                    ftp.enterRemotePassiveMode();
                }
                FTPFile[] ftpFiles = ftp.listFiles(basePath, new FTPFileFilter() {
                    @Override
                    public boolean accept(FTPFile file) {
                        if (file.getName().startsWith(softwareName)) {
                            return true;
                        } else {
                            return false;
                        }
                    }
                });
                if (ftpFiles.length > 0) {
                    FTPFile targetFile = ftpFiles[ftpFiles.length - 1];
                    System.out.println("targetFile : " + targetFile.getName() + " , " + targetFile.getSize()
                            + "!=" + new File(jarName).length());
                    if (!targetFile.getName().equals(jarName)
                            || targetFile.getSize() != new File(jarName).length()) {
                        int r = JOptionPane.showConfirmDialog(null,
                                "Confirm to update to " + targetFile.getName(), "Question",
                                JOptionPane.YES_NO_OPTION);
                        if (r == JOptionPane.YES_OPTION) {
                            //ftp.enterRemotePassiveMode();
                            d.progressBar.setString("downloading " + targetFile.getName());
                            ftp.setFileType(FTP.BINARY_FILE_TYPE);
                            ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE);

                            d.progressBar.setIndeterminate(false);
                            d.progressBar.setMaximum(100);
                            CopyStreamAdapter streamListener = new CopyStreamAdapter() {

                                @Override
                                public void bytesTransferred(long totalBytesTransferred, int bytesTransferred,
                                        long streamSize) {
                                    int percent = (int) (totalBytesTransferred * 100 / targetFile.getSize());
                                    d.progressBar.setValue(percent);
                                }
                            };
                            ftp.setCopyStreamListener(streamListener);
                            try (FileOutputStream fos = new FileOutputStream(targetFile.getName())) {
                                ftp.retrieveFile(basePath + "/" + targetFile.getName(), fos);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            d.progressBar.setString("restarting " + targetFile.getName());
                            restartApplication(targetFile.getName());
                        }
                    }

                }
                ftp.logout();
                ftp.disconnect();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
    d.thread = longRunningThread;
    d.setVisible(true);
}

From source file:net.sf.firemox.network.Client.java

@Override
public void run() {
    String entree;//w w  w .j  a v  a 2  s.  co m
    LoaderConsole.beginTask(LanguageManager.getString("wiz_network.creatingconnection") + "...", 2);
    InetAddress adr = null;
    try {
        // Connexion au serveur
        adr = InetAddress.getByName(Configuration.getString("ip"));
        clientSocket = new Socket(adr, port);
    } catch (IOException e) {
        // echec de la connexion au serveur
        JOptionPane.showMessageDialog(MagicUIComponents.magicForm,
                LanguageManager.getString("wiz_network.cannotconnectto", adr) + ", "
                        + LanguageManager.getString("wiz_network.port") + ":" + port + ". \n"
                        + LanguageManager.getString("wiz_network.port.invalid"),
                LanguageManager.getString("wiz_network.connectionpb"), JOptionPane.WARNING_MESSAGE);
        NetworkActor.cancelling = true;
        LoaderConsole.endTask();
    }

    // stopping?
    if (cancelling) {
        cancelConnexion();
        return;
    }
    LoaderConsole.beginTask(LanguageManager.getString("wiz_network.connecting"), 5);

    try {
        // Cration des flots d'entre/sortie
        outBin = clientSocket.getOutputStream();
        inBin = clientSocket.getInputStream();

        // need password?
        entree = MToolKit.readString(inBin);
        if (STR_PASSWD.equals(entree)) {
            // a password is need by this server
            if (passwd == null) {
                // ... but we haven't any
                LoaderConsole.beginTask(LanguageManager.getString("wiz_network.password.missed"));
                MToolKit.writeString(outBin, STR_NOPASSWD);
                // close stream
                IOUtils.closeQuietly(inBin);
                IOUtils.closeQuietly(outBin);
                // free pointers
                outBin = null;
                inBin = null;
            } else {
                // send our password
                MToolKit.writeString(outBin, new String(passwd));
                entree = MToolKit.readString(inBin);
                if (STR_WRONGPASSWD.equals(entree)) {
                    // wrong password
                    LoaderConsole.beginTask(LanguageManager.getString("wiz_network.password.invalid"));
                    // close stream
                    IOUtils.closeQuietly(inBin);
                    IOUtils.closeQuietly(outBin);
                    // free pointers
                    outBin = null;
                    inBin = null;
                }
            }
        }
        if (outBin != null && !STR_OK.equals(entree)) {
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.unknowncommand") + entree);
            // close stream
            IOUtils.closeQuietly(inBin);
            IOUtils.closeQuietly(outBin);
            // free pointers
            outBin = null;
            inBin = null;
        }
        if (outBin != null) {
            // send our version
            MToolKit.writeString(outBin, IdConst.VERSION);
            entree = MToolKit.readString(inBin);
            if (STR_WRONGVERSION.equals(entree)) {
                // wrong version
                LoaderConsole.beginTask(LanguageManager.getString("wiz_network.differentversionpb"));
                // close stream
                IOUtils.closeQuietly(inBin);
                IOUtils.closeQuietly(outBin);
                // free pointers
                outBin = null;
                inBin = null;
            }
        }
        if (outBin != null && !STR_OK.equals(entree)) {
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.unknowncommand") + entree);
            // close stream
            IOUtils.closeQuietly(inBin);
            IOUtils.closeQuietly(outBin);
            // free pointers
            outBin = null;
            inBin = null;
        }

        if (outBin != null) {
            /*
             * client is connected to the server client/serveur I am ...
             */
            MToolKit.writeString(outBin, nickName);
            // Opponent is ...
            String serverName = MToolKit.readString(inBin);
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.opponentis") + serverName, 10);

            // exchange shared string settings
            ((Opponent) StackManager.PLAYERS[1]).readSettings(serverName, nickName, inBin);
            ((You) StackManager.PLAYERS[0]).sendSettings(outBin);

            // stopping?
            if (cancelling) {
                cancelConnexion();
                return;
            }

            // receive, and set the random seed
            long seed = Long.parseLong(MToolKit.readString(inBin));
            MToolKit.random.setSeed(seed);
            Log.info("Seed = " + seed);

            // read mana use option
            PayMana.useMana = Integer.parseInt(MToolKit.readString(inBin)) == 1;

            // read opponent response option
            WaitActivatedChoice.opponentResponse = Integer.parseInt(MToolKit.readString(inBin)) == 1;

            // Who starts?
            final StartingOption startingOption = StartingOption.values()[Integer
                    .valueOf(MToolKit.readString(inBin)).intValue()];
            final boolean serverStarts;
            switch (startingOption) {
            case random:
            default:
                serverStarts = MToolKit.random.nextBoolean();
                break;
            case server:
                serverStarts = true;
                break;
            case client:
                serverStarts = false;
            }

            if (serverStarts) {
                // server begins
                LoaderConsole.beginTask(LanguageManager.getString("wiz_network.opponentwillstart") + " (mode="
                        + startingOption.getLocaleValue() + ")", 15);
                StackManager.idActivePlayer = 1;
                StackManager.idCurrentPlayer = 1;
            } else {
                // client begins
                LoaderConsole.beginTask(LanguageManager.getString("wiz_network.youwillstarts") + " (mode="
                        + startingOption.getLocaleValue() + ")", 15);
                StackManager.idActivePlayer = 0;
                StackManager.idCurrentPlayer = 0;
            }

            // load rules from the MDB file
            dbStream = MdbLoader.loadMDB(MToolKit.mdbFile, StackManager.idActivePlayer);
            TableTop.getInstance().initTbs();

            // send our deck
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.sendingdeck"), 25);
            deck.send(outBin);
            StackManager.PLAYERS[0].zoneManager.giveCards(deck, dbStream);
            MToolKit.writeString(outBin, "%EOF%");
            outBin.flush();

            // stopping?
            if (cancelling) {
                cancelConnexion();
                return;
            }

            // receive her/his deck
            LoaderConsole.beginTask(LanguageManager.getString("wiz_network.receivingdeck"), 55);
            readAndValidateOpponentDeck();

            // free resources
            LoaderConsole.setTaskPercent(100);

            // stopping?
            if (cancelling) {
                cancelConnexion();
                return;
            }

            // stopping?
            if (cancelling) {
                cancelConnexion();
                return;
            }

            initBigPipe();
            MagicUIComponents.magicForm.initGame();
        }
    } catch (Throwable e) {
        NetworkActor.cancelling = true;
        LoaderConsole.endTask();
        cancelConnexion();
        Log.error(e);
        throw new RuntimeException(LanguageManager.getString("wiz_network.badconnection", adr), e);
    }
}