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

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

        gui = new RomanNumeralGUI();

Edited by bdl365_1

5 Years
Discussion Span
Last Post by bdl365_1

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 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

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.