This is the simplest application to animate an array of images.

    import java.awt.*;
import javax.swing.*; public class AnimApp extends JComponent implements Runnable {
Image[] images = new Image[2];
int frame = 0; public void paint(Graphics g) {
Image image = images[frame];
if (image != null) {
// Draw the current image
int x = 0;
int y = 0;
g.drawImage(image, x, y, this);
}
} public void run() {
// Load the array of images
images[0] = new ImageIcon("image1.gif").getImage();
images[1] = new ImageIcon("image2.gif").getImage(); // Display each image for 1 second
int delay = 1000; // 1 second try {
while (true) {
// Move to the next image
frame = (frame+1)%images.length; // Causes the paint() method to be called
repaint(); // Wait
Thread.sleep(delay);
}
} catch (Exception e) {
}
} public static void main(String[] args) {
AnimApp app = new AnimApp(); // Display the animation in a frame
JFrame frame = new JFrame();
frame.getContentPane().add(app);
frame.setSize(300, 300);
frame.setVisible(true); (new Thread(app)).start();
}
}
Related Examples

e581. Animating an Array of Images in an Application的更多相关文章

  1. First Adventures in Google Closure -摘自网络

    Contents Introduction Background Hello Closure World Dependency Management Making an AJAX call with ...

  2. Framework for Graphics Animation and Compositing Operations

    FIELD OF THE DISCLOSURE The subject matter of the present disclosure relates to a framework for hand ...

  3. PHP HTTP请求

    stream_context_create 1.curl仍然是最好的HTTP库,没有之一. 可以解决任何复杂的应用场景中的HTTP 请求2. 文件流式的HTTP请求比较适合处理简单的HTTP POST ...

  4. 常用function() 收集

    1.随机数生成函数(来源-微信支付demo案例) /** * * 产生随机字符串,不长于32位 * @param int $length * @return 产生的随机字符串 */ public st ...

  5. php模拟http请求的方法

    我在这里终结了三种方法 第一种方法:fsockopen $flag = 0; $post = ''; $errno = ''; $errstr = ''; //要post的数据 $argv = arr ...

  6. TP5.0源生Excel导出

    PHPExcel类在TP5里边并不能很好的兼容,使用起来很麻烦. 不像是tp3.2那样直接import()加进来就能new,因为它里边的命名空间找不到.总是说undefined class. 如果是使 ...

  7. 淘宝SDK扒出来的CURL调用含文件上传代码

    <?php function curl($url,$postFields=null){ $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); c ...

  8. NSBundle

    属性: .使用类方法创建一个NSBundler对象 + (NSBundle *)mainBundle; eg:[NSBundle mailBundle]; .使用路径获取一个NSBundle 对象,这 ...

  9. 6种php发送get、post请求的方法简明归纳与示例

    方法1: 用file_get_contents 以get方式获取内容: <?php $url='http://www.jb51.net/'; $html = file_get_contents( ...

随机推荐

  1. NRF24L01使用外部中断读取数据的问题

    NRF24L01读取数据不能使用中断的方式,原因如下: 首先NRF24L01中断触发时,IRQ引脚会一直保持低电平直到状态寄存器中的中断标志被重新清零. stm32的外部中断触发方式只有上升沿或者下降 ...

  2. 编码规范:Eclipse Checkstyle配置

    http://chenzhou123520.iteye.com/blog/1627618 http://www.cnblogs.com/lanxuezaipiao/p/3202169.html

  3. 用jQuery.ajaxWebService请求WebMethod,Ajax处理实现局部刷新;及Jquery传参数,并跳转页面 用post传过长参数

    首先在aspx.cs文件里建一个公开的静态方法,然后加上WebMethod属性. 如: [WebMethod]  public static string GetUserName()   {  //. ...

  4. Javascript玩转继承(三)

    在前两篇文章中,介绍了构造继承和原型继承.今天把剩下的两种写完,这两种的应用相对于前两种来说应用很少,因此称为是非主流继承方式. 首先,来看非主流继承一:实例继承法.我也不说那么多废话了,既然是非主流 ...

  5. [svc]Iaas Paas Saas区别

    https://www.zhihu.com/question/20387284

  6. Windows下打造Sublime Text + Tex Live环境

    一直在用Sublime Text + ctex集成环境编写Latex文档,最近发现ctex套件内嵌的MiKTeX包管理器功能太弱了,遂将目标转向了功能更加强大的Tex Live环境. 首先安装Tex ...

  7. [Docker] Docker Hub加速

    一.缘由: 今天学习Flask,书上建议用Docker,那我就安装了DockerToolBox(WIN10系统只能用toolbox).其中从docker hub拉取ubuntu镜像时 docker p ...

  8. 说实话当一个程序猿不easy

    我以前说过,程序猿不是一般的人,是具有某种超能里的人.但问题是.程序猿往往意识不到自己的这样的特异功能.在他们的眼里.会觉得自己非常普通.跟常人一样,所以,程序猿能做到的事情,其它人--比方他们的客户 ...

  9. cocos2d-x笔记-CCGLProgram

    引擎提供了CCGLProgram类来处理着色器相关操作,对当前绘图程序进行了封装,其中使用频率最高的应该是获取着色器程序的接口: const GLuint getProgram(); 该接口返回了当前 ...

  10. markdown 语法简要备忘

    标题 # 一级标题 ## 二级标题 ### 三级标题 无序列表 前面加 - 或 * 即可变为 有序列表 直接用数字即可 1. 2. 3. 添加引用 > 图片与链接 插入链接与插入图片的语法很像, ...