Hey Guys,
i was looking at the post linked below and been trying to solve the issue, however, i have been unable to solve it.
The post says i "MUST create a new Vector for each row" in order for it to work. as mentioned above, i have tried doing this but failed.
Would really appreciate some help.
The code i have is displayed below:
package game;
import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class HighScores {
public static void main(String args[]) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Vector<String> v = new Vector<String>();
Vector<Vector<String>> myVector = new Vector<Vector<String>>();
try{
FileReader fReader = new FileReader("playerscores.txt");
BufferedReader inFile = new BufferedReader(fReader);
String input;
String[] temp;
while((input=inFile.readLine())!=null)
{
temp = input.split(",",6);
for(int i=0;i<temp.length;i++){
v.add(temp[i]);
System.out.println(temp[i]+" added");
}
System.out.println("V is "+v);
myVector.add(v);
System.out.println("---------End of Line");
Vector<String> columnNames = new Vector<String>();
columnNames.addElement("Player Name:");
columnNames.addElement("Score:");
JTable table = new JTable(myVector,columnNames);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(600, 150);
frame.setVisible(true);
}
}catch(Exception e){
System.out.println("ERROR");
}
}
}