Ok。だから私は、Java GUIのスイングアプリケーションを作成する必要があり、私は4つのjListsに列でtxtファイルからデータを渡そうとしています。 たとえば、私はこの行を私のtxtファイルに "John apples golden 15"と書いています。そして、私は4つの別々のjListsにそれぞれの単語を入れる必要があります。最初のリストのための私のコードは以下の通りです、今Imがjava gui .txtファイルの値を複数のjListsに渡す
for (Object item : itemList) {
;
}
で立ち往生
try {
BufferedReader buf = new BufferedReader(new FileReader("dfata.txt"));
ArrayList<String> words = new ArrayList<>();
String lineJustFetched = null;
String[] attributes;
while (true) {
lineJustFetched = buf.readLine();
if (lineJustFetched == null) {
break;
} else {
attributes = lineJustFetched.split("\t");
Item item = new Item(attributes[0], attributes[1], attributes[2], attributes[3], attributes[4]);
itemList.add(item);
}
}
buf.close();
} catch (Exception e) {
e.printStackTrace();
}
for (Object item : itemList) {
;
}
jListItemType.setModel(new javax.swing.AbstractListModel<String>() {
String[] strings = {""};
public int getSize() {
return strings.length;
}
public String getElementAt(int i) {
return strings[i];
}
});
class Item {
String id;
String type;
String model;
String size;
String color;
public Item(String id,String type, String model, String size, String color) {
this.id = id;
this.type = type;
this.model = model;
this.size = size;
this.color = color;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
「今、私は立ち往生しています...」 - 何とかしていますか?重要な詳細を教えてください。 –
これを使用してファイルからjListへの解析方法を知りません –