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());
     }
 }

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.