package com.animate;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Insets;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
public class Animate extends JFrame {
private static int DELAY = 100;
Insets insets;
Color colors[] = { Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN,
Color.BLUE, Color.MAGENTA };
public void paint(Graphics g) {
super.paint(g);
if (insets == null) {
insets = getInsets();
}
// Calculate each time in case of resize
int x = insets.left;
int y = insets.top;
int width = getWidth() - insets.left - insets.right;
int height = getHeight() - insets.top - insets.bottom;
int start = 0;
int steps = colors.length;
int stepSize = 360 / steps;
synchronized (colors) {
for (int i = 0; i < steps; i++) {
g.setColor(colors[i]);
g.fillArc(x, y, width, height, start, stepSize);
start += stepSize;
}
}
}
public void go() {
TimerTask task = new TimerTask() {
public void run() {
Color c = colors[0];
synchronized (colors) {
System.arraycopy(colors, 1, colors, 0, colors.length - 1);
colors[colors.length - 1] = c;
}
repaint();
}
};
Timer timer = new Timer();
timer.schedule(task, 0, DELAY);
}
public static void main(String args[]) {
Animate f = new Animate();
f.setSize(200, 200);
f.show();
f.go();
}
}
最近下载更多
tanhuizhao LV1
2021年10月21日
wwwwww777 LV2
2020年10月18日
chenweistudy LV2
2019年11月15日
Mr_小乔 LV2
2019年8月1日
Mississippi21 LV2
2019年5月30日
zy42735912 LV1
2018年4月8日
IVAM219 LV1
2017年11月1日
soda_soda LV1
2017年7月26日
LizRose LV1
2016年5月28日
barry2008 LV34
2014年12月15日
最近浏览更多
nnnnyyy LV1
2022年4月18日
微信网友_5852742079762432 LV6
2022年3月20日
香菇肉饼汤 LV8
2022年1月21日
本宝宝 LV2
2021年6月22日
xiajingbaobao
2021年4月12日
暂无贡献等级
1125521
2021年3月19日
暂无贡献等级
wwwwww777 LV2
2020年10月18日
zdm1230 LV2
2020年7月28日
爱死了李清照
2020年5月28日
暂无贡献等级
baizhongcai LV24
2020年5月3日

