별도의 줄에 저장된 텍스트 파일에서 개체 (실제로는 문자열이지만 개체로 변환)를 읽습니다.텍스트 파일에서 읽을 때 객체가 잘못 처리되는 이유는 무엇입니까?
EDIT : 내 문제는 개체가 패널에 추가 될 때 서로 겹쳐서 나오게된다는 것입니다. 객체는 자신의 별도의 X를 가지고 Y는 목록에 그려 질 예정중인 좌표과 같이
(이것이다 I에서 읽고 저장된 텍스트 파일).
Described,Bus,182,73,PlaceWithDesc,random desc
Named,Bus,53,31,Place1
Named,train,84,100,Place2
토큰 [0] 가
[1]
[2] (이 사진 패널 인출 될때 장소를 그 삼각형의 색상을 제공하는 목적이있다)는 전송의 종류는
단순한 하드 코딩 된 문자열 오브젝트의 x 좌표 Position과 [3]은 Y 좌표입니다.[4]는 개체를 구성 할 때의 장소 이름입니다.
[0]이 Described 인 경우 장소가 설명과 함께 만들어집니다.
FileReader inFile = new FileReader("place.reg");
BufferedReader in = new BufferedReader(inFile);
String line;
while ((line = in.readLine()) != null) {
String[] tokens = line.split(",");
Category category = null;
String categoryName = tokens[1];
if (categoryName.equals("Bus")) {
category = transportCategory[0];
} else if (categoryName.equals("Underground")) {
category = transportCategory[1];
} else if (categoryName.equals("Train")) {
category = transportCategory[2];
} else if (categoryName.equals("None")) {
category = transportCategory[3];
}
String placeName = tokens[0];
int x = Integer.parseInt(tokens[2]);
int y = Integer.parseInt(tokens[3]);
Position pos = new Position(x, y);
String name = tokens[4];
if (placeName.equals("Named")) {
NamedPlace nPlace = new NamedPlace(pos, category, name);
add(nPlace);
picturePanel.add(nPlace);
nPlace.addMouseListener(placeMouseLis);
System.out.println("named place added: " +
nPlace.position().getX() + " , " + pos.getX());
} else if (placeName.equals("Described")) {
String description = tokens[5];
DescribedPlace dPlace = new DescribedPlace(pos,
category, name, description);
add(dPlace);
picturePanel.add(dPlace);
System.out.println("desc place was added");
}
}
// Iterator<Map.Entry<Position, Place>> iterator =
// allPlaces.entrySet().iterator();
// while(iterator.hasNext()){
// Place place = iterator.next().getValue();
// picturePanel.add(place);
}
inFile.close();
in.close();
이제 제 문제는 장소 개체를 추가 할 때 서로의 위에 그려지는 점입니다. NamedPlace 및 DescribedPlace는 수퍼 클래스 Place의 하위 클래스입니다.
편집 : picturePanel.repaint();을 수행하여 문제를 해결했습니다. 및 picturePanel.validate();
아마도 당신이 설정 한 "경계"값을 무시하는 레이아웃에 대한 무언가. 한번보세요 : http://stackoverflow.com/questions/17264761/setbounds-not-working-for-jlabel-and-jbutton – DGardim