0

How do i pass file name ("chosenFileName") from sample2 class to sample1 class? An example would be nice.

here's some code from sample 2 class -

private void openFile( ) {
       JFileChooser chooser;
       int status;
       chooser = new JFileChooser( );
       status = chooser.showOpenDialog(null);
       if (status == JFileChooser.APPROVE_OPTION) 
          readSource(chooser.getSelectedFile());
       else 
          JOptionPane.showMessageDialog(null, "Open File dialog canceled");
    }

    private void readSource(File chosenFile) {
        String chosenFileName = chosenFile.getName();
        TextFileInput inFile = new TextFileInput(chosenFileName);
        String inputLine;

        inputLine = inFile.readLine();
        int arrayLength = 0;


        while (inputLine != null) {
            try {
                RomanNumeral romanNum = new RomanNumeral(inputLine);
                romanText[arrayLength++] = romanNum;
            } catch (IllegalArgumentException iae) {
            } finally {
                inputLine = inFile.readLine();

            }
        }
        inOrder = new RomanNumeralList();
        sorted = new RomanNumeralList();
        for(RomanNumeral romanNum : romanText) {
            if(romanNum != null) {
                inOrder.insert(romanNum);
                sorted.insert(romanNum);
            }
        }
        Collections.sort(sorted, new RomanNumeral());
     }
 }
3
Contributors
2
Replies
13
Views
3 Years
Discussion Span
Last Post by stultuske
0

simple..Define a constructor/function that accepts filename as parameter in simple1 class and now create the object of simple1 class by passing the filename as parameter.

0

well, if you can use JFileChooser, I just must assume you've heard of mutators (setters/getters) before? using those, you can "pass" values from one class to another.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.