Hey all
As Java is fairly new for me I have come into several problems.
First of all i have a program making a tab delimited file, for example like this:
Mig 12345 You
Gig 12345 Dou
Now i want to read the file and populate each line in the JTable.
But my problem is the transfer from file to object.. This is my code so far:
String[] kolonneNavne = {"Kursusnavn",
"Kursusnummer",
"Point",
"Skemaplacering",
"Liniefag",
"Kursus taget"};
Object[][] kdata ={{null,null,null,null,null,null}};
try {
BufferedReader buff = new BufferedReader(new FileReader("kurser.ini"));
String linie = buff.readLine();
StringTokenizer t = new StringTokenizer(linie, "\t", false);
String kursus[] = {null,null,null,null,null};
int antalKurser = 0;
while (linie != null){
kursus[0] = t.nextToken();
kursus[1] = t.nextToken();
kursus[2] = t.nextToken();
kursus[3] = t.nextToken();
kursus[4] = t.nextToken();
kdata[0][antalKurser] = kursus[0];
kdata[1][antalKurser] = kursus[1];
kdata[2][antalKurser] = kursus[2];
kdata[3][antalKurser] = kursus[3];
kdata[4][antalKurser] = kursus[4];
kdata[5][antalKurser] = new Boolean(false);
linie = buff.readLine();
antalKurser++;
}
}
catch (ArrayIndexOutOfBoundsException e){
}
catch (IOException e){
e.printStackTrace();
}
This should read every line in the file, and add the contents to
kdata
but it doesn't.
I've tried several things, reading the "How to Use tables" by java, and also looking at the Class "Scanner", but havn't got that working either.
I think that the error is in the assigning kursus[j] and kdata[][], but how do i do it? How kan i add contents to an array already having information:
Object[][] kdata;
?
Is there a smarter way?
Afterwards i do the essential:
final JTable table = new JTable(kdata, kolonneNavne);