Text File and JMenu

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2006
Posts: 114
Reputation: KimJack is an unknown quantity at this point 
Solved Threads: 0
KimJack KimJack is offline Offline
Junior Poster

Text File and JMenu

 
0
  #1
Aug 1st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 48
Reputation: sneaker is an unknown quantity at this point 
Solved Threads: 7
sneaker sneaker is offline Offline
Light Poster

Re: Text File and JMenu

 
0
  #2
Aug 3rd, 2009
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 =)
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 116
Reputation: KirkPatrick is an unknown quantity at this point 
Solved Threads: 4
KirkPatrick KirkPatrick is offline Offline
Junior Poster

Re: Text File and JMenu

 
0
  #3
Aug 3rd, 2009
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


  1. BufferedReader reader = new BufferedReader(new FileReader("C:\\myfile.fileExtension"));
  2.  
  3. ArrayList<String> list1 = new ArrayList<String>();
  4.  
  5. try {
  6. //this checks for headers, if you dont have them, ignore this part
  7. boolean bHeadersDone = false;
  8. while (reader.ready()) {
  9. String headerInfo = reader.readLine();
  10.  
  11. if (!bHeadersDone) {
  12. if (headerInfo.contains("Your last header here")) {
  13. bHeadersDone = true;
  14. }
  15. }
  16. else {
  17. //splitting file into 3 columns
  18. String[] info = list1Info.split("," , 3);
  19. Column1Info = info[0];
  20. Column2Info = info[1];
  21. Column3Info = info[2];
  22.  
  23. //adding columns to arraylist
  24. if(!list1.equals(0)) {
  25.  
  26. list1.add(itemA);
  27. list1.add(itemB);
  28. list1.add(itemC);
  29.  
  30. //do what you want here
  31. //maybe add them to jMenu here
  32. //catch exceptions

I hope that helps a little bit
Last edited by KirkPatrick; Aug 3rd, 2009 at 1:20 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 345 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC