943,907 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 504
  • Java RSS
Aug 1st, 2009
0

Text File and JMenu

Expand Post »
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
Similar Threads
Reputation Points: 8
Solved Threads: 0
Junior Poster
KimJack is offline Offline
114 posts
since Apr 2006
Aug 3rd, 2009
0

Re: Text File and JMenu

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 =)
Sponsor
Reputation Points: 40
Solved Threads: 13
Junior Poster in Training
sneaker is offline Offline
76 posts
since Jul 2009
Aug 3rd, 2009
0

Re: Text File and JMenu

Quote ...
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:
Quote ...
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


java Syntax (Toggle Plain Text)
  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.
Reputation Points: 38
Solved Threads: 8
Junior Poster
KirkPatrick is offline Offline
162 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: B.E project
Next Thread in Java Forum Timeline: Help needed in developing a software product





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC