2011-12-04 2 views
0

Timing Framework를 사용하는 작은 클래스가 있습니다 (http://java.net/projects/timingframework/).Java Timing Framework의 PropertySetter가 내 속성과 함께 작동하지 않습니다.

class Kula extends JPanel { 
private Animator an; 
private int xp; 
private int yp; 
private Color kolor; 

public Kula(int x, int y) { 
    this.xp = x; 
    this.yp = y; 
    this.kolor = Color.RED; 

    TimingTarget tt = PropertySetter.getTarget(this, "kolor", Color.RED, Color.BLUE); 
    an = new Animator.Builder().setDuration(2, TimeUnit.SECONDS).addTarget(tt).build(); 
} 

public Color getKolor() { 
    return kolor; 
} 

public void setKolor(Color kolor) { 
    this.kolor = kolor; 
    repaint(); 
} 

public Animator getAnimator() { 
    return this.an; 
} 

@Override 
public void paintComponent(Graphics g) { 
    super.paintComponent(g); 
    g.setColor(kolor); 
    g.fillOval(xp, yp, 20, 20); 
} 
} 

당신이 특정 색상 및 위치 (XP 및 YP)와 타원을 그립니다 볼 수 있듯이 : 여기에 코드입니다. Animator도 있습니다. 생성자에서 Animator를 만들지 만 선형 Interpolator (기본값)를 사용하여 kolor 변수를 변경하기 전에 TimingTarget을 만듭니다. 나는 getter와 setter를 가지고 있지만 내 애니메이션을 시작할 때 나는 예외 얻을 :

내가 선을 변경할 때, 흥미로운 무엇
 
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: (Timing Framework #31) An unexpected exception occurred when reflectively invoking the method setKolor on swingtest.GUI$Kula[,0,0,798x533,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=]. 
    at org.jdesktop.core.animation.timing.PropertySetter$PropertySetterTimingTarget.valueAtTimingEvent(PropertySetter.java:298) 
    at org.jdesktop.core.animation.timing.KeyFramesTimingTarget.timingEvent(KeyFramesTimingTarget.java:51) 
    at org.jdesktop.core.animation.timing.Animator.notifyListenersAboutATimingSourceTick(Animator.java:934) 
    at org.jdesktop.core.animation.timing.Animator.timingSourceTick(Animator.java:1124) 
    at org.jdesktop.core.animation.timing.TimingSource$1.run(TimingSource.java:183) 
    at org.jdesktop.swing.animation.timing.sources.SwingTimerTimingSource$1.actionPerformed(SwingTimerTimingSource.java:75) 
    at javax.swing.Timer.fireActionPerformed(Timer.java:312) 
    at javax.swing.Timer$DoPostEvent.run(Timer.java:244) 
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705) 
    at java.awt.EventQueue.access$000(EventQueue.java:101) 
    at java.awt.EventQueue$3.run(EventQueue.java:666) 
    at java.awt.EventQueue$3.run(EventQueue.java:664) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:675) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) 
Caused by: java.lang.IllegalAccessException: Class org.jdesktop.core.animation.timing.PropertySetter$PropertySetterTimingTarget can not access a member of class swingtest.GUI$Kula with modifiers "public" 
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:95) 
    at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261) 
    at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253) 
    at java.lang.reflect.Method.invoke(Method.java:594) 
    at org.jdesktop.core.animation.timing.PropertySetter$PropertySetterTimingTarget.valueAtTimingEvent(PropertySetter.java:296) 
    ... 21 more 

:

TimingTarget TT = PropertySetter.getTarget (이, "칼라"를 , Color.RED, Color.BLUE);

TimingTarget TT = PropertySetter.getTarget (이 "배경"Color.RED, Color.BLUE);

모두 괜찮습니다. 내 패널의 배경이 올바르게 변경됩니다.

내 PropertySetter가 kolor 변수와 작동하지 않는 이유는 무엇입니까?

P. 폴란드어로 "Kula"는 구체를 의미하고 "kolor"는 색상을 의미합니다.

답변

1

PropertySetter는 리플렉션을 통해 대상의 속성에 액세스합니다. 클래스와 속성 모두 공개 범위 인 경우에만 가능합니다.

  • 액세스 할 수 없습니다 : "칼라"는 패키지 범위 클래스의 공개 방법은 쿨라
  • 접근 : "배경"

해결하는 것입니다 공공 Component 클래스에있는 공공 방법 당신의 클래스 공개.

관련 문제