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.tapontikes.java.doUpload.java

public void checkExist() throws IOException {

    _ftp.changeWorkingDirectory("/public_html");

    String[] files = _ftp.listNames();

    if (Arrays.asList(files).contains(local_file.getName())) {
        JOptionPane.showMessageDialog(null, local_file.getName() + " already exists on the server.", "Alert!",
                JOptionPane.INFORMATION_MESSAGE);
        System.exit(0);/*from  w w  w .  j  a v a2 s.com*/
    }
    _ftp.changeWorkingDirectory("/");

}

From source file:edu.harvard.i2b2.query.QueryListNamesClient.java

public static String sendQueryRequestREST(String XMLstr) {
    try {//from  w  w w  . ja  v a 2 s  .  c o  m
        OMElement payload = getQueryPayLoad(XMLstr);
        Options options = new Options();
        targetEPR = new EndpointReference(getCRCNavigatorQueryProcessorServiceName());
        options.setTo(targetEPR);
        options.setTo(targetEPR);
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(10000));
        options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(10000));

        ServiceClient sender = new ServiceClient();
        sender.setOptions(options);

        OMElement result = sender.sendReceive(payload);
        //System.out.println("Response XML: "+result.toString());
        return result.toString();
    } catch (AxisFault axisFault) {
        axisFault.printStackTrace();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null,
                        "Trouble with connection to the remote server, "
                                + "this is often a network error, please try again",
                        "Network Error", JOptionPane.INFORMATION_MESSAGE);
            }
        });

        return null;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

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

/**
 * Constructor/*  w  w  w  .jav  a2  s  .c om*/
 * @param servername {@link String} Server name
 * @param port {@link String} Server Mysql Port
 * @param dbName {@link String} Database name
 * @param username {@link String} Mysql Username
 * @param password {@link String} Password
 */
public DatabaseManager(String servername, String port, String dbName, String username, String password) {
    this.servername = servername;
    this.port = port;
    this.url = "jdbc:mysql://" + servername + ":" + port + "/";
    this.dbName = dbName;
    this.userName = username;
    this.password = password;
    this.driver = "com.mysql.jdbc.Driver";
    try {
        Class.forName(driver).newInstance();
        conn = DriverManager.getConnection(url + dbName, userName, password);
    } catch (SQLException ex) {
        // handle any errors
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
        JOptionPane.showMessageDialog(null, "SQLException: " + ex.getMessage(), "Exception!",
                JOptionPane.ERROR_MESSAGE);
    } catch (ClassNotFoundException cs) {
        System.out.println("Class not found: " + cs.getMessage());
        JOptionPane.showMessageDialog(null, "Class not found: " + cs.getMessage(), "Exception!",
                JOptionPane.ERROR_MESSAGE);
    } catch (InstantiationException | IllegalAccessException i) {
        System.out.println("Instantiation/Illegal State Error: " + i.getMessage());
        JOptionPane.showMessageDialog(null, "Instantiation/Illegal State Error: " + i.getMessage(),
                "Exception!", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:edu.harvard.i2b2.query.QueryRequestClient.java

public static String sendQueryRequestREST(String XMLstr) {
    try {/*from  w w w  .j  a v  a 2  s .c  o  m*/
        OMElement payload = getQueryPayLoad(XMLstr);
        Options options = new Options();
        targetEPR = new EndpointReference(getCRCNavigatorQueryProcessorServiceName());
        options.setTo(targetEPR);
        options.setTo(targetEPR);
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(200000));
        options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(200000));

        ServiceClient sender = new ServiceClient();
        sender.setOptions(options);

        OMElement result = sender.sendReceive(payload);
        //System.out.println(result.toString());
        return result.toString();
    } catch (AxisFault axisFault) {
        axisFault.printStackTrace();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null,
                        "Trouble with connection to the remote server, "
                                + "this is often a network error, please try again",
                        "Network Error", JOptionPane.INFORMATION_MESSAGE);
            }
        });

        return null;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.intuit.tank.tools.debugger.SaveTextAction.java

/**
 * /*  w w w .  j  a v  a2  s.c om*/
 */
protected void showSaveDialog() {
    int response = saveAsChooser.showSaveDialog(parent);
    if (response == JFileChooser.APPROVE_OPTION) {
        File selectedFile = saveAsChooser.getSelectedFile();
        if (selectedFile.exists()) {
            int confirm = JOptionPane.showConfirmDialog(parent,
                    "Overwrite file " + selectedFile.getName() + "?");
            if (confirm != JOptionPane.YES_OPTION) {
                return;
            }
        }
        FileWriter fw = null;
        try {
            fw = new FileWriter(selectedFile);
            writer.writeText(fw);
        } catch (Exception e) {
            System.err.println("Error writing file: " + e.toString());
            e.printStackTrace();
            JOptionPane.showMessageDialog(parent, "Error writing file: " + e.toString(), "Error",
                    JOptionPane.ERROR_MESSAGE);
        } finally {
            IOUtils.closeQuietly(fw);
        }
    }

}

From source file:com.jug.MotherMachine.java

/**
 * PROJECT MAIN//from  w w w  .j  a  v a  2s. co  m
 * ============
 *
 * @param args
 *            muh!
 */
public static void main(final String[] args) {
    try {

        final MotherMachine main = new MotherMachine();
        guiFrame = new JFrame("Interactive MotherMachine");
        main.initMainWindow(guiFrame);

        props = main.loadParams();
        BGREM_TEMPLATE_XMIN = Integer
                .parseInt(props.getProperty("BGREM_TEMPLATE_XMIN", Integer.toString(BGREM_TEMPLATE_XMIN)));
        BGREM_TEMPLATE_XMAX = Integer
                .parseInt(props.getProperty("BGREM_TEMPLATE_XMAX", Integer.toString(BGREM_TEMPLATE_XMAX)));
        BGREM_X_OFFSET = Integer
                .parseInt(props.getProperty("BGREM_X_OFFSET", Integer.toString(BGREM_X_OFFSET)));
        GL_OFFSET_BOTTOM = Integer
                .parseInt(props.getProperty("GL_OFFSET_BOTTOM", Integer.toString(GL_OFFSET_BOTTOM)));
        GL_OFFSET_TOP = Integer.parseInt(props.getProperty("GL_OFFSET_TOP", Integer.toString(GL_OFFSET_TOP)));
        GL_OFFSET_LATERAL = Integer
                .parseInt(props.getProperty("GL_OFFSET_LATERAL", Integer.toString(GL_OFFSET_LATERAL)));
        MIN_CELL_LENGTH = Integer
                .parseInt(props.getProperty("MIN_CELL_LENGTH", Integer.toString(MIN_CELL_LENGTH)));
        MIN_GAP_CONTRAST = Double
                .parseDouble(props.getProperty("MIN_GAP_CONTRAST", Double.toString(MIN_GAP_CONTRAST)));
        SIGMA_PRE_SEGMENTATION_X = Double.parseDouble(
                props.getProperty("SIGMA_PRE_SEGMENTATION_X", Double.toString(SIGMA_PRE_SEGMENTATION_X)));
        SIGMA_PRE_SEGMENTATION_Y = Double.parseDouble(
                props.getProperty("SIGMA_PRE_SEGMENTATION_Y", Double.toString(SIGMA_PRE_SEGMENTATION_Y)));
        SIGMA_GL_DETECTION_X = Double
                .parseDouble(props.getProperty("SIGMA_GL_DETECTION_X", Double.toString(SIGMA_GL_DETECTION_X)));
        SIGMA_GL_DETECTION_Y = Double
                .parseDouble(props.getProperty("SIGMA_GL_DETECTION_Y", Double.toString(SIGMA_GL_DETECTION_Y)));
        DEFAULT_PATH = props.getProperty("DEFAULT_PATH", DEFAULT_PATH);

        GUI_POS_X = Integer.parseInt(props.getProperty("GUI_POS_X", Integer.toString(DEFAULT_GUI_POS_X)));
        GUI_POS_Y = Integer.parseInt(props.getProperty("GUI_POS_Y", Integer.toString(DEFAULT_GUI_POS_X)));
        GUI_WIDTH = Integer.parseInt(props.getProperty("GUI_WIDTH", Integer.toString(GUI_WIDTH)));
        GUI_HEIGHT = Integer.parseInt(props.getProperty("GUI_HEIGHT", Integer.toString(GUI_HEIGHT)));
        GUI_CONSOLE_WIDTH = Integer
                .parseInt(props.getProperty("GUI_CONSOLE_WIDTH", Integer.toString(GUI_CONSOLE_WIDTH)));
        // Iterate over all currently attached monitors and check if sceen position is actually possible,
        // otherwise fall back to the DEFAULT values and ignore the ones coming from the properties-file.
        boolean pos_ok = false;
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice[] gs = ge.getScreenDevices();
        for (int i = 0; i < gs.length; i++) {
            final DisplayMode dm = gs[i].getDisplayMode();
            if (gs[i].getDefaultConfiguration().getBounds()
                    .contains(new java.awt.Point(GUI_POS_X, GUI_POS_Y))) {
                pos_ok = true;
            }
        }
        // None of the screens contained the top-left window coordinates --> fall back onto default values...
        if (!pos_ok) {
            GUI_POS_X = DEFAULT_GUI_POS_X;
            GUI_POS_Y = DEFAULT_GUI_POS_Y;
        }

        String path = props.getProperty("import_path", System.getProperty("user.home"));
        final File fPath = main.showStartupDialog(guiFrame, path);
        path = fPath.getAbsolutePath();
        props.setProperty("import_path", fPath.getAbsolutePath());

        // Setting up console window and window snapper...
        main.initConsoleWindow();
        main.showConsoleWindow();
        final JFrameSnapper snapper = new JFrameSnapper();
        snapper.addFrame(main.frameConsoleWindow);
        snapper.addFrame(guiFrame);

        // ---------------------------------------------------
        main.processDataFromFolder(path);
        // ---------------------------------------------------

        System.out.print("Build and show GUI...");
        // show loaded and annotated data
        ImageJFunctions.show(main.imgRaw, "Rotated & cropped raw data");
        ImageJFunctions.show(main.imgTemp, "Temporary");
        ImageJFunctions.show(main.imgAnnotated, "Annotated ARGB data");

        final MotherMachineGui gui = new MotherMachineGui(new MotherMachineModel(main));
        gui.setVisible(true);

        main.ij = new ImageJ();
        guiFrame.add(gui);
        guiFrame.setSize(GUI_WIDTH, GUI_HEIGHT);
        guiFrame.setLocation(GUI_POS_X, GUI_POS_Y);
        guiFrame.setVisible(true);

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                snapper.snapFrames(main.frameConsoleWindow, guiFrame, JFrameSnapper.EAST);
            }
        });

        System.out.println(" done!");
    } catch (final UnsatisfiedLinkError ulr) {
        JOptionPane.showMessageDialog(MotherMachine.guiFrame,
                "Could initialize Gurobi.\n"
                        + "You might not have installed Gurobi properly or you miss a valid license.\n"
                        + "Please visit 'www.gurobi.com' for further information.\n\n" + ulr.getMessage(),
                "Gurobi Error?", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:de.cebitec.readXplorer.util.GeneralUtils.java

/**
 * @param parent the parent component//  w  w w. j  a v  a2 s  .  c  om
 * @return Any text found in the clipboard. If none is found, an empty
 * String is returned.
 */
public static String getClipboardContents(Component parent) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    String result = "";
    Transferable contents = clipboard.getContents(null);
    final boolean hasTransferableText = (contents != null)
            && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
    if (hasTransferableText) {
        try {
            result = (String) contents.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException ex) {
            JOptionPane.showMessageDialog(parent, "Unsupported DataFlavor for clipboard copying.",
                    "Paste Error", JOptionPane.ERROR_MESSAGE);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(parent,
                    "IOException occured during recovering of text from clipboard.", "Paste Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
    return result;
}

From source file:com.qspin.qtaste.testapi.impl.generic.UtilityImpl.java

public void showMessageDialog(final String title, final String message) throws QTasteException {
    try {/*w w w  . j  a v  a2 s .c  om*/
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(null, message, title, JOptionPane.PLAIN_MESSAGE);
            }
        });
    } catch (Exception e) {
        throw new QTasteException("Error while showing message dialog", e);
    }
}

From source file:com.redpill_linpro.libreoffice.LibreOfficeLauncherMacOSXImpl.java

@Override
public void launchLibreOffice(String cmisUrl, String repositoryId, String filePath, String webdavUrl) {

    Runtime rt = Runtime.getRuntime();
    try {// w  ww .  ja v a2 s.  c o m
        String params;
        if (null != webdavUrl && webdavUrl.length() > 0) {
            params = LibreOfficeLauncherHelper.generateLibreOfficeWebdavOpenUrl(webdavUrl);
        } else {
            params = LibreOfficeLauncherHelper.generateLibreOfficeCmisOpenUrl(cmisUrl, repositoryId, filePath);
        }
        StringBuffer cmd = new StringBuffer();
        try {
            String[] binaryLocations = { "/Applications/LibreOffice.app/Contents/MacOS/soffice" };
            cmd.append(binaryLocations[0] + " " + params);
            System.out.println("Command: " + cmd.toString());
            rt.exec(cmd.toString());

            System.out.println("Process started");
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, "Failed to start LibreOffice, commandline: " + cmd.toString(),
                    "Error", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }

    } catch (UnsupportedEncodingException e1) {
        JOptionPane.showMessageDialog(null, "Invalid URL for LibreOffice", "Error", JOptionPane.ERROR_MESSAGE);
        e1.printStackTrace();
    }
}

From source file:latexstudio.editor.remote.SaveProgress.java

@Override
public void actionPerformed(ActionEvent e) {
    DbxClient client = DbxUtil.getDbxClient();

    if (client == null) {
        return;//  w  w  w . j  a  v  a2  s.c  o  m
    }

    String sourceFileName = ApplicationUtils.getTempSourceFile();
    File file = new File(sourceFileName);

    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(file);
    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }

    DbxState dbxState = etc.getDbxState();

    if (dbxState != null) {
        try {
            DbxEntry.File uploadedFile = client.uploadFile(dbxState.getPath(),
                    DbxWriteMode.update(dbxState.getRevision()), file.length(), inputStream);
            JOptionPane.showMessageDialog(null,
                    "Successfuly updated file " + uploadedFile.name + " (" + uploadedFile.humanSize + ")",
                    "File updated in Dropbox", JOptionPane.INFORMATION_MESSAGE);
            drtc.updateRevisionsList(uploadedFile.path);
            etc.setDbxState(new DbxState(uploadedFile.path, uploadedFile.rev));
        } catch (DbxException ex) {
            DbxUtil.showDbxAccessDeniedPrompt();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    } else {
        JOptionPane.showMessageDialog(null,
                "No Dropbox file has been loaded.\n" + "You must open Dropbox file, before you save it.",
                "Cannot save progress", JOptionPane.WARNING_MESSAGE);
    }
}