📄 animation.java
字号:
package graphicAnimation;
import java.awt.Point;
/**
* 动画类,动画是指视图位置的连续变化,因此动画类保存其视图和动画路径信息,以及创建该动画的演示器
* @author 周晓聪
* @since 2007/7/15
*/
public class Animation {
protected Animator animator = null; // 创建动画的演示器
protected AnimationView viewer = null; // 动画的视图
protected AnimationPath path = null; // 动画路径
protected int delay = 2;
public Animation(Animator animator, AnimationView viewer) {
this.animator = animator;
this.viewer = viewer;
}
public Animation(Animator animator) {
this.animator = animator;
}
/**
* 返回创建动画的演示器
*/
public Animator getAnimator() {
return animator;
}
/**
* 设置创建动画的演示器
*/
public void setAnimator(Animator animator) {
this.animator = animator;
}
/**
* 返回动画的动画路径
*/
public AnimationPath getPath() {
return path;
}
/**
* 设置动画的动画路径,动画路径实际上就是视图连续变化的一系列位置坐标
*/
public void setPath(AnimationPath path) {
this.path = path;
}
/**
* 返回动画的视图
*/
public AnimationView getViewer() {
return viewer;
}
/**
* 设置动画的视图
*/
public void setViewer(AnimationView viewer) {
this.viewer = viewer;
}
/**
* 设置该动画自己独立运行时的步延迟
* @param delay
*/
public void setDelay(int delay) { this.delay = delay; }
/**
* 动画的运行可有两种方式,一种是一个动画独立运行,一种是将动画添加到动画驱动器中由动画驱动
* 器统一驱动运行。这里实现的是前一种方式,即当前动画独立地运行。当然动画独立运行时也可添加到
* 动画驱动器中去运行,不过那样可能消耗更多的CPU时间。
*
*/
public void run() {
for (int index = 0; index < path.size(); index++) {
Point pos = path.get(index);
viewer.moveTo(pos);
animator.update();
Animator.sleep(delay);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -