e581. Animating an Array of Images in an Application
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的更多相关文章
- First Adventures in Google Closure -摘自网络
Contents Introduction Background Hello Closure World Dependency Management Making an AJAX call with ...
- Framework for Graphics Animation and Compositing Operations
FIELD OF THE DISCLOSURE The subject matter of the present disclosure relates to a framework for hand ...
- PHP HTTP请求
stream_context_create 1.curl仍然是最好的HTTP库,没有之一. 可以解决任何复杂的应用场景中的HTTP 请求2. 文件流式的HTTP请求比较适合处理简单的HTTP POST ...
- 常用function() 收集
1.随机数生成函数(来源-微信支付demo案例) /** * * 产生随机字符串,不长于32位 * @param int $length * @return 产生的随机字符串 */ public st ...
- php模拟http请求的方法
我在这里终结了三种方法 第一种方法:fsockopen $flag = 0; $post = ''; $errno = ''; $errstr = ''; //要post的数据 $argv = arr ...
- TP5.0源生Excel导出
PHPExcel类在TP5里边并不能很好的兼容,使用起来很麻烦. 不像是tp3.2那样直接import()加进来就能new,因为它里边的命名空间找不到.总是说undefined class. 如果是使 ...
- 淘宝SDK扒出来的CURL调用含文件上传代码
<?php function curl($url,$postFields=null){ $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); c ...
- NSBundle
属性: .使用类方法创建一个NSBundler对象 + (NSBundle *)mainBundle; eg:[NSBundle mailBundle]; .使用路径获取一个NSBundle 对象,这 ...
- 6种php发送get、post请求的方法简明归纳与示例
方法1: 用file_get_contents 以get方式获取内容: <?php $url='http://www.jb51.net/'; $html = file_get_contents( ...
随机推荐
- 分享Memcached shell启动停止脚本
注意:要使用这个shell,必须先成功建立memcache环境 1>建立memcached文件和权限 [root@luozhonghua ~]# touch /etc/init.d/memcac ...
- 在Nodejs中贯彻单元测试
在团队合作中,你写好了一个函数,供队友使用,跑去跟你的队友说,你传个A值进去,他就会返回B结果了.过了一会,你队友跑过来说,我传个A值却返回C结果,怎么回事?你丫的有没有测试过啊? 大家一起写个项目, ...
- linux分享一:进程全攻略--守护进程(服务)
概括: 进程是程序的运行实例.进程对应一个唯一的进程PID, 统一程序的多个实例可以同时运行,他们的pid互不相同. 进程一般分为交互进程.批处理进程和守护进程(daemons)三类 一:什么是守护进 ...
- js实现页面时间动态变化
利用函数嵌套和setTimeout函数实现时间动态变化 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYe ...
- 关于modelsim时序仿真的几篇文章
1.http://wenku.baidu.com/view/386597f37c1cfad6195fa797.html 2.http://wenku.baidu.com/view/4b9521f9f7 ...
- 【Android】12.2 利用Intent启动和关闭Activity
分类:C#.Android.VS2015: 创建日期:2016-02-23 一.简介 Android应用程序中一般都有多个Activity,在Activity中,通过调用StartActivity方法 ...
- 【Android】6.2 AlertDialog(警告对话框)
分类:C#.Android.VS2015: 创建日期:2016-02-08 一.简介 AlertDialog也是Android系统当中常用的对话框之一. 在一个AlertDialog中,可以有一个Bu ...
- iOS登录单例
iOS登录单例 一,工程图. 二,代码. UserInfo.h #import <Foundation/Foundation.h> @interface UserInfo : NSObje ...
- dwz 取不到 form中的值
在使用dwz的时候,出现的一个问题, <li style=" width:160px;"> <label style=" width:60px;&quo ...
- C_文件包含.h文件和包含.c文件总结
很多人对C语言中的 “文件包含”都不陌生了,文件包含处理在程序开发中会给我们的模块化程序设计带来很大的好处,通过文件包含的方法把程序中的各个功能模块联系起来是模块化程序设计中的一种非常有利的手段. 文 ...