Ok. 그래서 자바 GUI 스윙 어플 리케이션을 만들 필요가 있고, 4 jLists로 열에 의해 txt 파일에서 데이터를 전달하려고 해요. 예를 들어,이 행은 내 txt 파일에서 "John apples golden 15"이며 각 단어를 4 개의 개별 jLists에 넣어야합니다. 첫 번째 목록에 대한 내 코드는 다음과 같습니다, 지금 임은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로 구문 분석하는 방법을 모른다. –