私はcsvファイルから読み込み、次にStringTokenizerを使って要素を切り詰めてJLabelsに配置するプロジェクトに取り組んでいます。これまで私はその部分を持っています。私は各位置をスクロールするためのボタンを持っていますが、フィールドに入力して配列に追加する方法についてはわかりません。arraylistに追加する方法
これは、これまで
// program reads in csvfile.
private void loadCarList() {
try{
BufferedReader CSVFile = new BufferedReader(new FileReader("car.txt"));
String dataRow = CSVFile.readLine();
while(dataRow != null){
carList.add(dataRow);
dataRow = CSVFile.readLine();
}
}catch(Exception e){
System.out.println("Exception while reading csv file: " + e);
}
}
}
//this will click cycle through the elements in the Jlabels.
private void loadNextElement(){
try {
StringTokenizer st = new StringTokenizer((String)carList.get(position), ",");
while(st.hasMoreTokens() && position <= carList.size() -1) {
position ++;
String CarID = st.nextToken();
String DealerShipID = st.nextToken();
String ColorID = st.nextToken();
String Year = st.nextToken();
String Price = st.nextToken();
String Quantity = st.nextToken();
tCarID.setText(CarID);
tDealerShip.setText(DealerShipID);
tColor.setText(ColorID);
tYear.setText(Year);
tPrice.setText(Price);
tQuantity.setText(Quantity);
}
} catch(Exception e){
JOptionPane.showMessageDialog(null, "youve reached the end of the list");
}
}
私のプログラムの主要部分、私はちょうど私がレイアウトされているのJLabelを入力し、アレイ上に追加できる簡単な方法がありますか?
私はこの時点でかなり迷っています。これをさらに進める方法は不明です。
スタイルコメント:クラスではないものの名前を大文字にしないでください。それは読者(構文ハイライターと同様に)を混乱させます。 – Taymon
申し訳ありませんが、あなたが何を求めているのかは分かりません。リストはどこにありますか、それに何を追加したいですか? – Taymon