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. mysql按日/周/月统计

    一.mysql按日统计 ) count ' and start_time > '2017-06-28' group by days; 二.mysql按周统计 ) ' group by weeks ...

  2. springboot admin

    转 Spring Boot Admin的使用 作者 杜琪 关注 2015.12.25 17:30* 字数 1803 阅读 16569评论 21喜欢 55 上一篇文章中了解了Spring Boot提供的 ...

  3. jquery插件Flot的简单讲解

    只是说一下基本用法,举一两个例子,详细用法请查看官方文档 使用方法是要先引入jquery插件,然后引入flot插件. <script type="text/javascript&quo ...

  4. textureCache中的等价路径问题

    自己的引擎里做了个简单的TextueCache,每次新创建一个纹理,先到TextureCache里查找有没有路径相同的,如果有就直接返回纹理,如果没有加载图片创建纹理并将图片路径缓存起来.另外为了标准 ...

  5. 关于WCF服务的调试跟踪

    关于WCF服务的调试跟踪信息,请利用好以下几个工具,具体的例子MSDN上都有,进去看吧... 服务跟踪查看器工具 (SvcTraceViewer.exe): http://msdn.microsoft ...

  6. opencv源代码之中的一个:cvboost.cpp

    我使用的是opencv2.4.9.安装后.我的cvboost..cpp文件的路径是........\opencv\sources\apps\haartraining\cvboost.cpp.研究源代码 ...

  7. 基于FPGA的异步FIFO验证

    现在开始对上一篇博文介绍的异步FIFO进行功能验证,上一篇博文地址:http://blog.chinaaet.com/crazybird/p/5100000872 .对异步FIFO验证的平台如图1所示 ...

  8. Flask教程 —— Web表单(上)

    第二章中介绍的request对象公开了所有客户端发送的请求信息.特别是request.form可以访问POST请求提交的表单数据. 尽管Flask的request对象提供的支持足以处理web表单,但依 ...

  9. org.apache.commons

    Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.我选了一些比较常用的项目做简单介绍. 一.Commons BeanUtils http://jakar ...

  10. jQuery (一)选择器

    上一章开始了jQuery的安装,这一张需要开始学习选择器了,不然不进行选择,就无法使用jQuery提供的库的功能不是. 常用的,就列举这么多吧 <!DOCTYPE html> <ht ...