| | |
Text File and JMenu
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2006
Posts: 114
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Apr 2009
Posts: 116
Reputation:
Solved Threads: 4
•
•
•
•
My question is that instead of reading to the console how would I get this informaton into the JMenus.
•
•
•
•
jMenu1:
Bike
Car
jMenu2:
Schwinn
Mercedes
jMenu3:
45.00
98,000
*edit*
Here is an example snippet to help you understand
java Syntax (Toggle Plain Text)
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
Last edited by KirkPatrick; Aug 3rd, 2009 at 1:20 pm.
![]() |
Similar Threads
- connect to text file database (Visual Basic 4 / 5 / 6)
- Output in Text file-How to apply fprintf()? (C)
- Output in the text file (C)
- Create stats from a text file (Java)
- Store Bluetooth remote address to a text file (C++)
- 10 line text file (Java)
- Read and write to an ASCII Text file (Java)
Other Threads in the Java Forum
- Previous Thread: B.E project
- Next Thread: Help needed in developing a software product
Views: 345 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api appinventor apple applet application arguments array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component database draw eclipse error event exception file fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaprojects jetbrains jmf jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie notdisplaying number object oracle page print problem program programming project qt recursion scanner screen server set size sms socket sort spamblocker sql string swing system test threads time transfer tree variablebinding windows xor





