CSV ファイルからデータを取得し、それを 2 次元配列に解析してから、それを JTable に表示する GUI に戻そうとしています。あまりうまくいっていないようです!
CSVから取得する方法
static String[][] readGUIFromPropertyFile(String sFileName, String userName) throws FileNotFoundException
{
String thisLine;
String tempArray[][] = new String[20][4];
int i = 0;
BufferedReader reader = new BufferedReader(new FileReader(sFileName));
try
{
while((thisLine = reader.readLine()) != null)
{
String propertyDetails[] = thisLine.split(",");
if (propertyDetails[0].equals(userName))
{
tempArray[i][0] = propertyDetails[1];
tempArray[i][1] = propertyDetails[2];
tempArray[i][2] = propertyDetails[3];
tempArray[i][3] = propertyDetails[4];
tempArray[i][4] = propertyDetails[5];
i++;
}
}
return tempArray;
}
catch(IOException e)
{
System.out.print("\nProperties do not exist\n");
e.printStackTrace();
}
finally{
try
{ reader.close();
}catch (IOException e){}}
return tempArray;
}
}
GUI のコード
else if (event.getSource() == reload)
{
try {
data = CSVWrite.readGUIFromPropertyFile(propertyFile, userName);
JOptionPane.showMessageDialog(frame, "Properties Loaded");
userPropertyView.add(displayProperties);
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(frame, "Properties Not Loaded");
e.printStackTrace();
}
}
コマンド インターフェイスで動作しているので、コードが動作していることはわかっていますが、GUI とコマンド ラインの両方を実装する必要があります。GUI から CSV に書き込むことはできますが、問題はありませんが、表示に問題があります。私はArrayListsを調べましたが、実際に明日それらについての講義があるので、それも可能です。
これにはデフォルトのライブラリを使用する必要があるため、OpenCSV を使用できません。