Color 클래스 생성자는 RGB 값만을 파라미터로 받으니 귀찮은 데이터 전환을 해야 하나 고민하다가... 다음 메소드를 이용하면 된다는 걸 알았다.
Color color = Color.decode("00FF66");
그런데 예외가 발생했다. 앞에 #을 붙여 주어야 했다.
Color color = Color.decode("#00FF66");
그런데 스택트레이스 덕분에
Exception in thread "main" java.lang.NumberFormatException: For input string: "0ff66"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:458)
at java.lang.Integer.valueOf(Integer.java:528)
at java.lang.Integer.decode(Integer.java:958)
at java.awt.Color.decode(Color.java:707)
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:458)
at java.lang.Integer.valueOf(Integer.java:528)
at java.lang.Integer.decode(Integer.java:958)
at java.awt.Color.decode(Color.java:707)
실제로는 Integer 클래스의 decode 메소드를 사용하면 된다는 것도 알았다.
No comments:
Post a Comment