Hi,

I really hope that someone can give me a little advice. I am working on a program that reads a text file formatted as follows:

Bike, Schwinn, 45.00
Car, Mercedes, 98,000
...

I am writing a program that will read this text file and write each item in a seperate JMenu for user selection. For example each JMenu will house one column of information.

So far I have created the JMenus, added them to a frame and am reading the file to the console. My question is that instead of reading to the console how would I get this informaton into the JMenus. I am using the BufferedReader and the FileReader to read the file and using a StringTokenizer to parse the lines.

Any suggestions will be great.

KimJack

Hi

I am not sure that I understand your problem.
Do you want the information to be showed in a text area in your GUI when someone select the proper menu? Or how do you mean?

Please explain a little bit more =)

My question is that instead of reading to the console how would I get this informaton into the JMenus.

Are you wanting to have 3 jMenus reading like so:

jMenu1:
Bike
Car

jMenu2:
Schwinn
Mercedes

jMenu3:
45.00
98,000

If thats how you are wanting them split, then split them using "," and specify each column, perhaps save each to an arraylist, and then have your menus get the value based on column.


*edit*
Here is an example snippet to help you understand

BufferedReader reader = new BufferedReader(new FileReader("C:\\myfile.fileExtension"));

        ArrayList<String> list1 = new ArrayList<String>();

        try {
            //this checks for headers, if you dont have them, ignore this part
            boolean bHeadersDone = false;
            while (reader.ready()) {
                String headerInfo = reader.readLine();

                if (!bHeadersDone) {
                    if (headerInfo.contains("Your last header here")) {
                        bHeadersDone = true;
                    }
                }
                else {
                    //splitting file into 3 columns
                    String[] info = list1Info.split("," , 3);
                    Column1Info = info[0];
                    Column2Info = info[1];
                    Column3Info = info[2];
                    
                    //adding columns to arraylist
                    if(!list1.equals(0)) {

                        list1.add(itemA);
                        list1.add(itemB);
                        list1.add(itemC);

                        //do what you want here
                        //maybe add them to jMenu here
                        //catch exceptions

I hope that helps a little bit

This question has already been answered. Start a new discussion instead.