0
我正在从csv文件中读取项目,然后使用StringTokenizer将元素截断并将它们放入JLabels中。到目前为止,我已经放弃了这部分。我有按钮滚动浏览每个位置,但我不确定如何输入字段并将其添加到数组中?如何添加到数组列表
这是我的计划的主要部分至今
// 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 2012-04-08 02:50:45
对不起,但我不能告诉你在问什么。清单的确切位置,以及您想要追加的内容? – Taymon 2012-04-08 02:57:03