我想为 JLabel 添加动画效果,因为我正在使用这个库:http ://www.aurelienribon.com/blog/projects/universal-tween-engine/ 。
但是这段代码不会产生动画。我知道我做错了。请提供正确的方法。我已阅读此页面上的教程https://code.google.com/p/java-universal-tween-engine/wiki/GetStarted。但我仍然无法弄清楚......
public class ParticleAccessor extends javax.swing.JFrame implements TweenAccessor<JLabel>{
public ParticleAccessor() {
initComponents();
}
private void initComponents() {
}
public static void main(String args[]) {
/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
ParticleAccessor pa = new ParticleAccessor();
pa.setVisible(true);
TweenManager m = new TweenManager();
Tween.registerAccessor(JLabel.class, pa);
Tween.to(particle1, ParticleAccessor.POSITION_XY, 1.0f)
.target(100, 200)
.start(m);
Tween.to(particle2, ParticleAccessor.POSITION_XY, 0.5f)
.target(0, 0)
.ease(Bounce.OUT)
.delay(1.0f)
.repeatYoyo(2, 0.5f)
.start();
m.update(50);
}
});
}
// Variables declaration - do not modify
private static javax.swing.JLabel particle1;
private static javax.swing.JLabel particle2;
// End of variables declaration
public static final int POSITION_X = 1;
public static final int POSITION_Y = 2;
public static final int POSITION_XY = 3;
// TweenAccessor implementation
@Override
public int getValues(JLabel target, int tweenType, float[] returnValues) {
switch (tweenType) {
case POSITION_X: returnValues[0] = target.getX(); return 1;
case POSITION_Y: returnValues[0] = target.getY(); return 1;
case POSITION_XY:
returnValues[0] = target.getX();
returnValues[1] = target.getY();
return 2;
default: assert false; return -1;
}
}
@Override
public void setValues(JLabel target, int tweenType, float[] newValues) {
switch (tweenType) {
case POSITION_X: target.setAlignmentX(newValues[0]); break;
case POSITION_Y: target.setAlignmentY(newValues[0]); break;
case POSITION_XY:
target.setAlignmentX(newValues[0]);
target.setAlignmentY(newValues[1]);
break;
default: assert false; break;
}
}
}