import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//动画图标
//Download by http://www.codefans.net
public class AnimatorIcon extends JPanel implements ActionListener {
ImageIcon[] images; //用于动画的图标数组
Timer animationTimer;
int currentImage = 0; //当前图像编号
int delay = 500; //图像切换延迟
int width; //图像宽度
int height; //图像高度
public AnimatorIcon() //构造函数
{
setBackground(Color.white);
images = new ImageIcon[2]; //初始化数组
for (int i=0;i<images.length;i++)
images[i]=new ImageIcon(getClass().getResource("image"+i+".gif")); //实例化图标
width = images[0].getIconWidth(); //初始化宽度值
height = images[0].getIconHeight(); //初始化高度值
}
public void paintComponent(Graphics g) { //重载组件绘制方法
super.paintComponent(g); //调用父类函数
images[currentImage].paintIcon(this,g,70,0); //绘制图标
currentImage=(currentImage+1)%2; //更改当前图像编号
}
public void actionPerformed(ActionEvent actionEvent) {
repaint();
}
public void startAnimation() { //开始动画
if (animationTimer==null) {
currentImage=0;
animationTimer=new Timer(delay, this); //实例化Timer对象
animationTimer.start(); //开始运行
} else if (!animationTimer.isRunning()) //如果没有运行
animationTimer.restart(); //重新运行
}
public void stopAnimation() {
animationTimer.stop(); //停止动画
}
public static void main(String args[]) {
AnimatorIcon animation = new AnimatorIcon(); //实例化动画图标
JFrame frame = new JFrame("动画图标"); //实例化窗口对象
frame.getContentPane().add(animation); //增加组件到窗口上
frame.setSize(200, 100); //设置窗口尺寸
frame.setVisible(true); //设置窗口可视
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序
animation.startAnimation(); //开始动画
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于java的开发源码-Jav动画图标源码(显示GIF图像).zip
共10个文件
gif:6个
bmp:2个
class:1个
1 下载量 2 浏览量
2024-01-08
20:36:18
上传
评论
收藏 34KB ZIP 举报
温馨提示
基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip 基于java的开发源码-Jav动画图标源码(显示GIF图像).zip
资源推荐
资源详情
资源评论
收起资源包目录
基于java的开发源码-Jav动画图标源码(显示GIF图像).zip (10个子文件)
codefans.net
Java动画图标
image0.gif 5KB
image3.gif 5KB
image4.gif 5KB
image1.gif 5KB
24-1.bmp 59KB
image5.gif 4KB
AnimatorIcon.class 2KB
24-2.bmp 59KB
AnimatorIcon.java 2KB
image2.gif 5KB
共 10 条
- 1
资源评论
快乐无限出发
- 粉丝: 1126
- 资源: 7260
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功