The problem is reading back an r,g,b and setting the r,g,b into a setBackground colour when reading from a csv file (comma separated values file) but the csv file also has text in it that needs to be set to the text fields.
the save button saves the file into a csv format that then needs to be read back into the fields which is just a 2d array of text fields.
public void writeDataFile(String fileName)
{
try
{
BufferedWriter outFile = new BufferedWriter(new FileWriter("e:\\EmissionsTracker.csv"));
for (int x = 0; x < totalX; x++)
{
for (int y = 0; y < totalY ; y++)
{
outFile.write(fields[0][y].getText() + "," + fields[x][0].getText() + "," + fields[x][y].getText() + ",");
outFile.write(fields[x][y].getBackground() + ",");
outFile.newLine();
}
}
outFile.close();
}
public void saveEmmisionsTableToFile(String fileName)
{
try
{
BufferedWriter outFile = new BufferedWriter(new FileWriter(fileName));
for (int y = 0; y < totalY; y++)
{
for (int x = 0; x < totalX; x++)
{
outFile.write(fields[x][y].getBackground() + "," );
}
outFile.newLine();
}
outFile.close();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
private void readDataFile(String fileName)
{
try
{
BufferedReader br = new BufferedReader(new FileReader(fileName));
for (int x = 0; x < totalX; x++)
{
for (int y = 0; y < totalY; y++)
{
String temp[] = br.readLine().split(",");
fields[x][y].setText(temp[5]);
}
}
br.close();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}