私はTiming Frameworkを使用して小さなクラスをhttp://java.net/projects/timingframework/から持っています。コードは次のとおりです。Javaタイミングフレームワークの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を作成しますが、TimingTargetを作成して線形インターポレータ(デフォルト)を使用してkolor変数を変更する前に作成します。私はゲッターとセッターを持っていますが、私は私のアニメーターを起動したとき、私は例外を取得:
私はラインを変更すると、興味深い何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(この、「KOLOR」を、Color.RED、Color.BLUE);
TimingTarget TT = PropertySetter.getTarget(この、 "背景"、Color.RED、Color.BLUE)に
。
すべてが問題ありません。私のパネルの背景が正しく変更されます。
なぜ私のPropertySetterがkolor変数で動作しないのですか?
P. "Kula"は球を意味し、 "kolor"は色を意味します。