| | |
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: 359 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arguments array arrays automation bidirectional binary birt bluetooth calculator chat class classes client code columns component database designadrawingapplicationusingjavajslider detection draw eclipse editor error errors event exception expand file fractal game givemetehcodez graphics gui guidancer helpwithhomework html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jmf jni jpanel julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie number object oracle os plazmic print problem program programming project recursion scanner screen server set signing size smart sms smsspam socket sort sql string subclass support swing test threads time transfer tree windows





