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:ch.zhaw.iamp.rct.weights.Weights.java

/**
 * Calculates a pseudo-inverse using the values in the given files. They are
 * first read, then converted to a matrix, and finally used for the
 * calculation of the inverse, using Singular value decomposition (SVD).
 *
 * @param pathToA The file which contains the matrix A, represented in
 * comma-separated-value format./*from www .  j ava2 s . c  om*/
 * @param targetTrajectoryFile The file which contains the target
 * trajectory, represented in comma-separated-value format.
 * @param weightsFile The file, to which the calculated weights should be
 * written to.
 * @param offset The numbers of first steps to ignore (to skip fading-memory
 * initialization steps).
 */
public static void calculateWeights(final String pathToA, final String targetTrajectoryFile,
        final String weightsFile, final int offset) {
    try {
        RealMatrix A = csvToMatrix(pathToA);
        // cut first n elements
        A = A.getSubMatrix(offset, A.getRowDimension() - 1, 0, A.getColumnDimension() - 1);
        A = addNoise(A);

        RealMatrix b = csvToMatrix(targetTrajectoryFile);

        // adjust b to cutting
        int n = offset % b.getRowDimension();

        if (n > 0) {
            RealMatrix tmp = b.getSubMatrix(n, b.getRowDimension() - 1, 0, b.getColumnDimension() - 1);
            b = b.getSubMatrix(0, n - 1, 0, b.getColumnDimension() - 1);
            double[][] tmpArray = tmp.getData();
            double[][] tmpArray2 = b.getData();
            b = MatrixUtils.createRealMatrix(concat(tmpArray, tmpArray2));
            tmpArray = b.getData();

            for (int i = 0; tmpArray.length < A.getRowDimension(); ++i) {
                tmpArray2 = new double[1][tmpArray[0].length];

                for (int j = 0; j < tmpArray[i].length; ++j) {
                    tmpArray2[0][j] = tmpArray[i][j];
                }

                tmpArray = concat(tmpArray, tmpArray2);
            }

            b = MatrixUtils.createRealMatrix(tmpArray);
        }

        DecompositionSolver solver = new SingularValueDecomposition(A).getSolver();
        RealMatrix x = solver.solve(b).transpose();
        matrixToCsv(x, weightsFile);

    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "Could not read a file: " + ex.getMessage(), "File Error",
                JOptionPane.ERROR_MESSAGE);
        Logger.getLogger(Weights.class.getName()).log(Level.WARNING, "Could not read a file: {0}", ex);
    } catch (DimensionMismatchException ex) {
        JOptionPane.showMessageDialog(null,
                "<html>Could not calculate the " + "pseudo-inverse since a dimension mismatch occurred.<br />"
                        + "Please make sure that all lines of the CSV file posses "
                        + "the same amount of entries.<br />Hint: Remove the last "
                        + "line and try it again.</html>",
                "Matrix Dimension Mismatch", JOptionPane.ERROR_MESSAGE);
        Logger.getLogger(Weights.class.getName()).log(Level.WARNING, "A dimension mismatch occurred: {0}", ex);
    }
}

From source file:biz.wolschon.finance.jgnucash.actions.ToolPluginMenuAction.java

@Override
public void actionPerformed(final ActionEvent e) {
    try {/*from w  ww. ja  va2  s.  c  o m*/
        GnucashWritableFile wModel = myJGnucashEditor.getWritableModel();
        if (wModel == null) {
            JOptionPane.showMessageDialog(myJGnucashEditor, "No open file.",
                    "Please open a gnucash-file first!", JOptionPane.WARNING_MESSAGE);
            return;
        }

        // Activate plug-in that declares extension.
        myJGnucashEditor.getPluginManager().activatePlugin(ext.getDeclaringPluginDescriptor().getId());
        // Get plug-in class loader.
        ClassLoader classLoader = myJGnucashEditor.getPluginManager()
                .getPluginClassLoader(ext.getDeclaringPluginDescriptor());
        // Load Tool class.
        Class toolCls = classLoader.loadClass(ext.getParameter("class").valueAsString());
        // Create Tool instance.
        Object o = toolCls.newInstance();
        if (!(o instanceof ToolPlugin)) {
            LOGGER.error("Plugin '" + pluginName + "' does not implement ToolPlugin-interface.");
            JOptionPane.showMessageDialog(myJGnucashEditor, "Error",
                    "Plugin '" + pluginName + "' does not implement ToolPlugin-interface.",
                    JOptionPane.ERROR_MESSAGE);
            return;

        }
        ToolPlugin importer = (ToolPlugin) o;
        try {
            myJGnucashEditor.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            GnucashWritableAccount selectedAccount = (GnucashWritableAccount) myJGnucashEditor
                    .getSelectedAccount();
            String message = importer.runTool(wModel, selectedAccount);
            if (message != null && message.length() > 0) {
                JOptionPane.showMessageDialog(myJGnucashEditor, "Tool OK",
                        "The tool-use was a success:\n" + message, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e1) {
            LOGGER.error("Tool-use via Plugin '" + pluginName + "' failed.", e1);
            JOptionPane
                    .showMessageDialog(
                            myJGnucashEditor, "Error", "Tool-use via Plugin '" + pluginName + "' failed.\n"
                                    + "[" + e1.getClass().getName() + "]: " + e1.getMessage(),
                            JOptionPane.ERROR_MESSAGE);
        } finally {
            myJGnucashEditor.setCursor(Cursor.getDefaultCursor());
        }
    } catch (Exception e1) {
        LOGGER.error("Could not activate requested Tool-plugin '" + pluginName + "'.", e1);
        JOptionPane
                .showMessageDialog(
                        myJGnucashEditor, "Error", "Could not activate requested Tool-plugin '" + pluginName
                                + "'.\n" + "[" + e1.getClass().getName() + "]: " + e1.getMessage(),
                        JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java

public static boolean checkVOExists(String voName, String server) {
    boolean isExist = false;
    String voDir = vomsdir + File.separator + voName;
    String voFilelsc = voDir + File.separator + server + ".lsc";
    if (new File(voDir).isDirectory()) {
        if (new File(voFilelsc).isFile()) {
            isExist = true;/*from   w w w . j a v  a2 s.  com*/
            JOptionPane.showMessageDialog(null,
                    "This VO '" + voName + "' with server '+ server +' already exists.", "Error: Add new VO",
                    JOptionPane.ERROR_MESSAGE);
        }

    }

    return isExist;
}

From source file:biz.wolschon.finance.jgnucash.actions.ImportPluginMenuAction.java

@Override
public void actionPerformed(final ActionEvent e) {
    try {/*from  ww w  .  j a  v  a  2 s.co  m*/
        GnucashWritableFile wModel = myJGnucashEditor.getWritableModel();
        if (wModel == null) {
            JOptionPane.showMessageDialog(myJGnucashEditor, "No open file.",
                    "Please open a gnucash-file first!", JOptionPane.WARNING_MESSAGE);
            return;
        }

        // Activate plug-in that declares extension.
        myJGnucashEditor.getPluginManager().activatePlugin(ext.getDeclaringPluginDescriptor().getId());
        // Get plug-in class loader.
        ClassLoader classLoader = myJGnucashEditor.getPluginManager()
                .getPluginClassLoader(ext.getDeclaringPluginDescriptor());
        // Load Tool class.
        Class toolCls = classLoader.loadClass(ext.getParameter("class").valueAsString());
        // Create Tool instance.
        Object o = toolCls.newInstance();
        if (!(o instanceof ImporterPlugin)) {
            LOGGER.error("Plugin '" + pluginName + "' does not implement ImporterPlugin-interface.");
            JOptionPane.showMessageDialog(myJGnucashEditor, "Error",
                    "Plugin '" + pluginName + "' does not implement ImporterPlugin-interface.",
                    JOptionPane.ERROR_MESSAGE);
            return;

        }
        ImporterPlugin importer = (ImporterPlugin) o;
        try {
            myJGnucashEditor.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            GnucashWritableAccount selectedAccount = (GnucashWritableAccount) myJGnucashEditor
                    .getSelectedAccount();
            String message = importer.runImport(wModel, selectedAccount);
            if (message != null && message.length() > 0) {
                JOptionPane.showMessageDialog(myJGnucashEditor, "Import OK",
                        "The import was a success:\n" + message, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e1) {
            LOGGER.error("Import via Plugin '" + pluginName + "' failed.", e1);
            JOptionPane
                    .showMessageDialog(
                            myJGnucashEditor, "Error", "Import via Plugin '" + pluginName + "' failed.\n" + "["
                                    + e1.getClass().getName() + "]: " + e1.getMessage(),
                            JOptionPane.ERROR_MESSAGE);
        } finally {
            myJGnucashEditor.setCursor(Cursor.getDefaultCursor());
        }
    } catch (Exception e1) {
        LOGGER.error("Could not activate requested import-plugin '" + pluginName + "'.", e1);
        JOptionPane
                .showMessageDialog(
                        myJGnucashEditor, "Error", "Could not activate requested import-plugin '" + pluginName
                                + "'.\n" + "[" + e1.getClass().getName() + "]: " + e1.getMessage(),
                        JOptionPane.ERROR_MESSAGE);
    }
}

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

/**
 * Constructor/*from  w w w.  j  a  v  a  2s  . c  o m*/
 * @param tables {@link List} List of source tables
 */
public TableRelationsForm(List tables, SchemerMapper parent) {
    fileManager = null;
    dbManager = null;
    emrConn = null;
    this.parent = parent;
    this.tables = tables; //source tables

    //Create KenyaEMR DB connection
    fileManager = new FileManager();
    String[] settings = fileManager.getConnectionSettings("emr_database.properties", "emr");
    if (settings == null) {
        //Connection settings not found
        JOptionPane.showMessageDialog(null,
                "Database Settings not found. Please set the connection settings for the database first.",
                "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
        //Open KenyaEMRConnectionForm form
    } else {
        if (settings.length < 1) {
            JOptionPane.showMessageDialog(null,
                    "Database Settings not found. Please set the connection settings for the database first.",
                    "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
            //Open KenyaEMRConnectionForm form
        } else {
            //Connection settings are ok
            //We establish a connection
            dbManager = new DatabaseManager(settings[0], settings[1], settings[3], settings[4], settings[5]);
            emrConn = dbManager.getConnection();
            if (emrConn == null) {
                JOptionPane.showMessageDialog(null, "Test Connection Failed", "Connection Test",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    //get all columns and add them to the columns list
    for (Object table : tables) {
        String tablename = (String) table;
        populateTableColumnsToList(tablename);
    }

    model = new DefaultTableModel(
            new Object[] { "Primary Table", "Column", "Reference Table", "Foreign Column" }, 10);

    initComponents();
    this.setClosable(true);
    foreignTables = tables;
    combo1 = new JComboBox();//Combobox for the primary tables
    combo2 = new JComboBox();
    combo3 = new JComboBox();
    combo4 = new JComboBox();
    combo1.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate primary table columns
                primaryColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo2_model = new DefaultComboBoxModel(
                        primaryColumns.toArray(new String[primaryColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo2_model);
                relationsTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox));

            }
        }
    });

    combo3.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate foreign table columns
                foreignColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo3_model = new DefaultComboBoxModel(
                        foreignColumns.toArray(new String[foreignColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo3_model);
                relationsTable.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBox));
            }
        }
    });
    ComboBoxTableCellEditor primaryTableEditor = new ComboBoxTableCellEditor(tables, combo1);
    ComboBoxTableCellEditor primaryTableColumns = new ComboBoxTableCellEditor(primaryColumns, combo2);

    ComboBoxTableCellEditor foreignTableEditor = new ComboBoxTableCellEditor(foreignTables, combo3);//TODO: remove selected primary table from list

    ComboBoxTableCellEditor foreignTableColumns = new ComboBoxTableCellEditor(foreignColumns, combo4);
    relationsTable.getColumnModel().getColumn(0).setCellEditor(primaryTableEditor);
    relationsTable.getColumnModel().getColumn(1).setCellEditor(primaryTableColumns);
    relationsTable.getColumnModel().getColumn(2).setCellEditor(foreignTableEditor);
    relationsTable.getColumnModel().getColumn(3).setCellEditor(foreignTableColumns);

    columnsList.setCellRenderer(new CheckboxListCellRenderer());
    SourceTablesListener listSelectionListener = new SourceTablesListener(new JTextArea(), selected_columns);
    columnsList.addListSelectionListener(listSelectionListener);
    columnsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    columnsList.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (isSelectedIndex(index0))
                super.removeSelectionInterval(index0, index1);
            else
                super.addSelectionInterval(index0, index1);
        }
    });
}

From source file:mobac.program.EnvironmentSetup.java

/**
 * In case the <tt>mapsources</tt> directory has been moved by configuration (directories.ini or settings.xml) we
 * need to copy the existing map packs into the configured directory
 *///w w w .java  2 s .  c  om
public static void copyMapPacks() {
    File userMapSourcesDir = Settings.getInstance().getMapSourcesDirectory();
    File progMapSourcesDir = new File(DirectoryManager.programDir, "mapsources");
    if (userMapSourcesDir.equals(progMapSourcesDir))
        return; // no user specific directory configured
    if (userMapSourcesDir.isDirectory())
        return; // directory already exists - map packs should have been already copied
    try {
        Utilities.mkDirs(userMapSourcesDir);
        FileUtils.copyDirectory(progMapSourcesDir, userMapSourcesDir, new FileExtFilter(".jar"));
    } catch (IOException e) {
        log.error(e);
        JOptionPane.showMessageDialog(null, "Error on initializing mapsources directory:\n" + e.getMessage(),
                "Error", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
}

From source file:net.sf.jabref.external.MoveFileAction.java

@Override
public void actionPerformed(ActionEvent event) {
    int selected = editor.getSelectedRow();

    if (selected == -1) {
        return;//from  w w  w . j av a 2s . c  o m
    }

    FileListEntry entry = editor.getTableModel().getEntry(selected);

    // Check if the current file exists:
    String ln = entry.link;
    boolean httpLink = ln.toLowerCase(Locale.ENGLISH).startsWith("http");
    if (httpLink) {
        // TODO: notify that this operation cannot be done on remote links
        return;
    }

    // Get an absolute path representation:
    List<String> dirs = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectory();
    int found = -1;
    for (int i = 0; i < dirs.size(); i++) {
        if (new File(dirs.get(i)).exists()) {
            found = i;
            break;
        }
    }
    if (found < 0) {
        JOptionPane.showMessageDialog(frame, Localization.lang("File_directory_is_not_set_or_does_not_exist!"),
                MOVE_RENAME, JOptionPane.ERROR_MESSAGE);
        return;
    }
    File file = new File(ln);
    if (!file.isAbsolute()) {
        file = FileUtil.expandFilename(ln, dirs).orElse(null);
    }
    if ((file != null) && file.exists()) {
        // Ok, we found the file. Now get a new name:
        String extension = null;
        if (entry.type.isPresent()) {
            extension = "." + entry.type.get().getExtension();
        }

        File newFile = null;
        boolean repeat = true;
        while (repeat) {
            repeat = false;
            String chosenFile;
            if (toFileDir) {
                // Determine which name to suggest:
                String suggName = FileUtil
                        .createFileNameFromPattern(eEditor.getDatabase(), eEditor.getEntry(),
                                Globals.journalAbbreviationLoader, Globals.prefs)
                        .concat(entry.type.isPresent() ? "." + entry.type.get().getExtension() : "");
                CheckBoxMessage cbm = new CheckBoxMessage(Localization.lang("Move file to file directory?"),
                        Localization.lang("Rename to '%0'", suggName),
                        Globals.prefs.getBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR));
                int answer;
                // Only ask about renaming file if the file doesn't have the proper name already:
                if (suggName.equals(file.getName())) {
                    answer = JOptionPane.showConfirmDialog(frame,
                            Localization.lang("Move file to file directory?"), MOVE_RENAME,
                            JOptionPane.YES_NO_OPTION);
                } else {
                    answer = JOptionPane.showConfirmDialog(frame, cbm, MOVE_RENAME, JOptionPane.YES_NO_OPTION);
                }
                if (answer != JOptionPane.YES_OPTION) {
                    return;
                }
                Globals.prefs.putBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR, cbm.isSelected());
                StringBuilder sb = new StringBuilder(dirs.get(found));
                if (!dirs.get(found).endsWith(File.separator)) {
                    sb.append(File.separator);
                }
                if (cbm.isSelected()) {
                    // Rename:
                    sb.append(suggName);
                } else {
                    // Do not rename:
                    sb.append(file.getName());
                }
                chosenFile = sb.toString();
            } else {
                chosenFile = FileDialogs.getNewFile(frame, file, Collections.singletonList(extension),
                        JFileChooser.SAVE_DIALOG, false);
            }
            if (chosenFile == null) {
                return; // canceled
            }
            newFile = new File(chosenFile);
            // Check if the file already exists:
            if (newFile.exists() && (JOptionPane.showConfirmDialog(frame,
                    Localization.lang("'%0' exists. Overwrite file?", newFile.getName()), MOVE_RENAME,
                    JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION)) {
                if (toFileDir) {
                    return;
                } else {
                    repeat = true;
                }
            }
        }

        if (!newFile.equals(file)) {
            try {
                boolean success = file.renameTo(newFile);
                if (!success) {
                    success = FileUtil.copyFile(file, newFile, true);
                }
                if (success) {
                    // Remove the original file:
                    if (!file.delete()) {
                        LOGGER.info("Cannot delete original file");
                    }
                    // Relativise path, if possible.
                    String canPath = new File(dirs.get(found)).getCanonicalPath();
                    if (newFile.getCanonicalPath().startsWith(canPath)) {
                        if ((newFile.getCanonicalPath().length() > canPath.length()) && (newFile
                                .getCanonicalPath().charAt(canPath.length()) == File.separatorChar)) {

                            String newLink = newFile.getCanonicalPath().substring(1 + canPath.length());
                            editor.getTableModel().setEntry(selected,
                                    new FileListEntry(entry.description, newLink, entry.type));
                        } else {
                            String newLink = newFile.getCanonicalPath().substring(canPath.length());
                            editor.getTableModel().setEntry(selected,
                                    new FileListEntry(entry.description, newLink, entry.type));
                        }

                    } else {
                        String newLink = newFile.getCanonicalPath();
                        editor.getTableModel().setEntry(selected,
                                new FileListEntry(entry.description, newLink, entry.type));
                    }
                    eEditor.updateField(editor);
                    //JOptionPane.showMessageDialog(frame, Globals.lang("File moved"),
                    //        Globals.lang("Move/Rename file"), JOptionPane.INFORMATION_MESSAGE);
                    frame.output(Localization.lang("File moved"));
                } else {
                    JOptionPane.showMessageDialog(frame, Localization.lang("Move file failed"), MOVE_RENAME,
                            JOptionPane.ERROR_MESSAGE);
                }

            } catch (SecurityException | IOException ex) {
                LOGGER.warn("Could not move file", ex);
                JOptionPane.showMessageDialog(frame,
                        Localization.lang("Could not move file '%0'.", file.getAbsolutePath())
                                + ex.getMessage(),
                        MOVE_RENAME, JOptionPane.ERROR_MESSAGE);
            }

        }
    } else {
        // File doesn't exist, so we can't move it.
        JOptionPane.showMessageDialog(frame, Localization.lang("Could not find file '%0'.", entry.link),
                Localization.lang("File not found"), JOptionPane.ERROR_MESSAGE);
    }

}

From source file:com.stefanbrenner.droplet.ui.actions.SaveFileAction.java

protected void showFileChooser() {
    int returnVal = fileChooser.showSaveDialog(getFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        // Get the selected file
        File file = fileChooser.getSelectedFile();

        // check if file extension fits
        if (StringUtils.containsIgnoreCase(file.getName(), ".") //$NON-NLS-1$
                && !(StringUtils.endsWithIgnoreCase(file.getName(),
                        "." + IDropletContext.DROPLET_FILE_EXTENSION))) {
            JOptionPane.showMessageDialog(getFrame(), Messages.getString("SaveFileAction.extensionNotAllowed"), //$NON-NLS-1$
                    Messages.getString("SaveFileAction.wrongExtension"), //$NON-NLS-1$
                    JOptionPane.ERROR_MESSAGE);
            showFileChooser();//from w  w w.  j a v a 2 s .c  o  m
            return;
        } else { // automatically add droplet file extension
            if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + IDropletContext.DROPLET_FILE_EXTENSION)) {
                String newPath = StringUtils.join(file.getPath(), "." + IDropletContext.DROPLET_FILE_EXTENSION);
                file = new File(newPath);
            }
        }

        // check if file already exists
        if (file.exists()) {
            int retVal = JOptionPane.showConfirmDialog(getFrame(),
                    Messages.getString("SaveFileAction.overwriteFile"), Messages.getString("SaveFileAction.1"), //$NON-NLS-1$ //$NON-NLS-2$
                    JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

            if (retVal == JOptionPane.NO_OPTION) {
                showFileChooser();
                return;
            }
        }

        saveFile(file);

        // set file to context
        getDropletContext().setFile(file);

    }
}

From source file:view.statistics.RequestStatsAndPrediction.java

/**
 * Creates new form PredictRequests/*from   w  w w  .java  2  s .co  m*/
 */
public RequestStatsAndPrediction() throws FileNotFoundException, IOException {
    initComponents();
    FileInputStream imgStream = null;
    File imgfile = new File("..\\BBMS\\src\\images\\drop.png");
    imgStream = new FileInputStream(imgfile);
    BufferedImage bi = ImageIO.read(imgStream);
    ImageIcon myImg = new ImageIcon(bi);
    this.setFrameIcon(myImg);
    setTitle("Request Statistics and Prediction");
    sdcontroller = new SampleDetailsController();
    Calendar calendar = Calendar.getInstance();
    yearChooser.setStartYear(calendar.get(Calendar.YEAR));
    monthChooser.setMonth(calendar.get(calendar.MONTH) + 1);

    int year = yearChooser.getYear();
    int month = monthChooser.getMonth() + 1;

    int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    int currentMonth = Calendar.getInstance().get(Calendar.MONTH) + 1;

    int data[][] = null;

    try {
        data = sdcontroller.getYearlyRequestCountsOf(month);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
    }

    if (year >= currentYear && month >= currentMonth) {

        try {
            predictText.setText(Predictions.getPredictedRequestsOf(year, month) + "");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        JOptionPane.showMessageDialog(this,
                "Predictions available only for future months. Only the graph will be drawn", "Error",
                JOptionPane.ERROR_MESSAGE);
        predictText.setText("Invalid input!");
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (data != null) {
        for (int i = 0; i < data[0].length; i++) {
            dataset.setValue(data[1][i], "Bla bla bla", data[0][i] + "");
        }
    }

    JFreeChart chart = ChartFactory.createLineChart3D(
            "Yearly Blood Request Count For The Month of " + getMontName(month + ""), "Year", "Request Count",
            dataset, PlotOrientation.VERTICAL, false, true, false);
    chart.setBackgroundPaint(Color.PINK);
    chart.getTitle().setPaint(Color.RED);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLUE);

    ChartPanel panel = new ChartPanel(chart);
    panel.setPreferredSize(new java.awt.Dimension(200, 350));
    chartAreaPanel.setLayout(new GridLayout());
    chartAreaPanel.removeAll();
    chartAreaPanel.revalidate();
    chartAreaPanel.add(panel);
    chartAreaPanel.repaint();

    this.repaint();

}

From source file:components.PasswordDemo.java

public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();

    if (OK.equals(cmd)) { //Process the password.
        char[] input = passwordField.getPassword();
        if (isPasswordCorrect(input)) {
            JOptionPane.showMessageDialog(controllingFrame, "Success! You typed the right password.");
        } else {/*from w w w .  j  a v a  2  s . co  m*/
            JOptionPane.showMessageDialog(controllingFrame, "Invalid password. Try again.", "Error Message",
                    JOptionPane.ERROR_MESSAGE);
        }

        //Zero out the possible password, for security.
        Arrays.fill(input, '0');

        passwordField.selectAll();
        resetFocus();
    } else { //The user has asked for help.
        JOptionPane.showMessageDialog(controllingFrame,
                "You can get the password by searching this example's\n"
                        + "source code for the string \"correctPassword\".\n"
                        + "Or look at the section How to Use Password Fields in\n"
                        + "the components section of The Java Tutorial.");
    }
}