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) 
          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) {
        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.

This article has been dead for over six months. Start a new discussion instead.