Hi guys, I'm currently making a GUI which displays a graph. At the moment it reads coordinates within an array in the code:
public int datax[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
public int datay[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
I need it to take these coordinates from a txt file, which I'm having trouble with.
So far I've made it read in a txt file and output to a text area like this:
public void readFile() {
// Disable read button
readFile.setEnabled(false);
// Dimension data structure
getNumberOfLines();
data = new String[numLines];
// Read file
readTheFile();
// Output to text area
textArea.setText(data[0] + "\n");
for(int index=1; index < data.length;index++)
textArea.append(data[index] + "\n");
// Rnable open button
openFile.setEnabled(true);
}
My code to plot the coordinates using datasets is this:
//Configure dataset
int n = 10;
Dataset dataset = new Dataset (1, 2, n);
for (int k = 0; k < n; ++k)
dataset.set(0, 0, k, datax[k]);
for (int k = 0; k < n; ++k)
dataset.set(0, 1, k, datay[k]);
I need datax and datay to be read in from the txt file though which is formatted simply x val, y val [per line]
3, 4
2, 6
5, 9 etc..
Even if it read the file into an array, then outputted this to the graph, that would work! I know this should be straightforward, but I just can't see how to do it. Some areas of Java I get, others I definately don't :cry: Can anyone possibly suggest a solution?
Thanks
Lev