Let me start by saying I'm a noob.

I want to get input from a text file through gui and perform some actions.the last time I did it I used command line argument to pass file name to get file input. The code in quote.
It works when I uncomment it and use command line argument. But since I want gui to handle that; what kind of changes do i need to make?

FYI: There are other classes which I haven't attached.

public class sample {
    public static final int MAX_ROMAN_NUMERALS = 1000;
    public static RomanNumeralGUI gui; 

    public static void main (String[] args) {
        String inputLine;
        int arrayLength = 0;
        RomanNumeral myRomanNumeral;
        RomanNumeral[] romanNumeralList = new RomanNumeral[MAX_ROMAN_NUMERALS];

        //  If there is no command line argument for the file name a message will be
        //  displayed and the program terminated.
       /* if (args.length == 0) {
        JOptionPane.showMessageDialog(null," There is no input file given on the command line.");
        System.exit(0);
        }
        */
        TextFileInput in = new TextFileInput(args[0]);
        inputLine = in.readLine();
        while (inputLine != null) {
            try {
                myRomanNumeral = new RomanNumeral(inputLine);
                romanNumeralList[arrayLength++] = myRomanNumeral;
            } catch (IllegalArgumentException iae) {
            } finally {
                inputLine = in.readLine();
            }
        }

        RomanNumeralList inOrder = new RomanNumeralList(), sorted = new RomanNumeralList();

        for (RomanNumeral romanNumeral : romanNumeralList) {
            if (romanNumeral != null) {
                inOrder.insert(romanNumeral);
                sorted.insert(romanNumeral);
            }
        }

        Collections.sort(sorted, new RomanNumeral());

        gui = new RomanNumeralGUI();
        gui.setVisible(true);        
    }  
}

Check the JOptionPane documentation. There's a method that allows you to give a prompt (eg "Enter file name") and get the answer back in a String

I want user to select file through gui by browsing.

read up on JFileChooser. look here

i have a fileMenuHandler class that handles eveything(read file and put it in array)..I want to pass the fileName to main..an example would be really appreciated

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.