2011-04-27 3 views
4

drawString과 같은 Graphics2D 메서드 중 일부는 좌표가 int 또는 float 인 버전이 있습니다. 하나를 선택할 이유가 있습니까?Graphics2D : int 또는 float 버전을 사용해야합니까?

마찬가지로, I는 (부동 소수점 좌표를 사용) 등 Rectangle2D 같은 새로운 Shape 클래스를 사용하거나 Rectangle을 (S int으로 좌표를 정의하는)를 사용합니까?

답변

4

나는 INT 볼 플로트 -

drawString(AttributedCharacterIterator iterator, float x, float y) 
Renders the text of the specified iterator, using the Graphics2D context's current Paint. 

drawString(AttributedCharacterIterator iterator, int x, int y) 
Renders the text of the specified iterator, using the Graphics2D context's current Paint. 

사용 플로트를 사용하면 위치가 충분할 경우 INT, 더 정밀도를 필요로하는 경우. 두 번째 질문 그 이하가 다음으로/기술 대답했다 참조하십시오에 관한

, Rectangle and Rectangle2D Difference :

사각형 INT 좌표를 사용합니다. Rectangle2D는 int, double 또는 float 좌표를 사용하는지 신경 쓰지 않는 추상 클래스입니다.

double과 float의 정밀도가 더 필요하면 Rectangle2D를 사용해야합니다.

의 Rectangle2D는 기본 클래스입니다, 그래서 당신은 추상적 인 방법으로 직사각형 형태에서 작동 코드를 작성하는 경우, Rectangle2D를 가고, 그래서 같이 할당 :

Rectangle2D rect = new Rectangle2D.Double(double, double, double, double); 

또는

Rectangle2D rect = new Rectangle(int, int, int, int) 

int를 처리하는 경우에만 Rectangle을 사용할 수 있습니다.

Rectangle을 Rectangle2D.Integer라고해야 할 수도 있습니다. 하지만 그것은 그다지 중요하지 않습니다. 직사각형은 직렬화 가능 인터페이스를 구현하는 3 개 중 유일하게 하나입니다.

skaffman이 댓글을 달았 듯이, 약간의 유산 문제입니다.

+0

대단히 감사합니다. (방금 포스트 수정, * float * not double) –

관련 문제