0

I have created a Java desktop program , with the help of JFreeChart libraries. I can open a stock data file (symbol.txt) and have the program display a couple of indicators. I want to create an explorer in a new JFrame window that will open a folder with stock data files and check some indicator value. My problem is to find a way to open multiple files at once (at the user level) but process every file one after the other at the program level (open first file, check indicator, close first file...continue with second file). Thank you.

Update after some hours :

Here is a first attempt , which produces a org.jfree.data.general.SeriesException error when I am trying to open more than one file.

You are attempting to add an observation for the time period 4-January-2011
but the series already contains an observation for that time period.
Duplicates are not permitted.  Try using the addOrUpdate() method.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nysemarketpick;

import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author skiabox
 */
public class ExplorerForm extends javax.swing.JFrame {

    PriceVolumeChart chart;

    /**
     * Creates new form ExplorerForm
     */
    public ExplorerForm() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        fileChooser = new javax.swing.JFileChooser();
        scrollPane = new javax.swing.JScrollPane();
        textArea = new javax.swing.JTextArea();
        fileMenuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openItem = new javax.swing.JMenuItem();

        fileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
        fileChooser.setMultiSelectionEnabled(true);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Stock Explorer");

        textArea.setColumns(20);
        textArea.setRows(5);
        scrollPane.setViewportView(textArea);

        fileMenu.setText("File");

        openItem.setText("Open");
        openItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openItemActionPerformed(evt);
            }
        });
        fileMenu.add(openItem);

        fileMenuBar.add(fileMenu);

        setJMenuBar(fileMenuBar);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(scrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 314, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(80, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(75, 75, 75)
                .add(scrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(103, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void openItemActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION)
        {
            File files[];

            //File myFile;

            files = fileChooser.getSelectedFiles();

            for (int i = 0; i < files.length; i++)
            {
                //myFile = files
                chart = new PriceVolumeChart(files[i].getAbsolutePath());

                System.out.println(files[i].getAbsolutePath());

                if (chart.getTLDirection().equals("(-1)"))
                {
                    textArea.append(files[i].getAbsolutePath() + "\n");
                }

                chart = null;
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ExplorerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ExplorerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ExplorerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ExplorerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ExplorerForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenuBar fileMenuBar;
    private javax.swing.JMenuItem openItem;
    private javax.swing.JScrollPane scrollPane;
    private javax.swing.JTextArea textArea;
    // End of variables declaration
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
skiabox
  • 3,449
  • 12
  • 63
  • 95
  • It is the class that creates a chart along with the indicators and then passes a JPane.Do you want me to paste the code? – skiabox Jul 09 '12 at 07:01
  • I found a solution....the reply is coming in about an hour or so...stay tuned. – skiabox Jul 09 '12 at 07:43
  • I just moved a static object intance creation of a time series, from the class variable list , into the class constructor (PriceVolumeChart), so that the timeseries object is contructed every time , for every single stock file. – skiabox Jul 09 '12 at 09:18
  • I will post the code of the solution in a moment as a reply – skiabox Jul 09 '12 at 09:19

1 Answers1

2

JInternalFrame may be a good choice. Examples may be found here and here. Use Action to keep your menus and documents organized, as shown here and here.

image

Addendum: I am talking about 3200 files.

JTable is a good choice for this order of magnitude. Use a custom editor to create a button that acts on a particular row. Multiple selections can use a ListSelectionListener, shown here, or check boxes, shown here.

image

Addendum: You can open JFileChooser in a modal dialog, seen here in an AbstractAction, or embedded in the frame, as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I am talking about 3200 files.So I don't want to display any chart.I just want to add the filenames of the charts that meet my criteria to a textbox. – skiabox Jul 08 '12 at 18:49