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( ...
随机推荐
- 实战:MySQL Sending data导致查询很慢的问题详细分析(转)
这两天帮忙定位一个MySQL查询很慢的问题,定位过程综合各种方法.理论.工具,很有代表性,分享给大家作为新年礼物:) [问题现象] 使用sphinx支持倒排索引,但sphinx从mysql查询源数据的 ...
- html5中script的async属性
html5中script的async属性 我兴奋于html5的原因之一是一些久久未能实现的特性现在可以真正运用于实际项目中了. 如我们使用placeholder效果蛮久了但是那需要javascript ...
- JS 中document.URL 和 windows.location.href 的区别
实际上,document 和 windows 这两个对象的区别已经包含了这个问题的答案. document 表示的是一个文档对象,windows 表示一个窗口对象. 一个窗口下面可以有很多的docu ...
- 在FPGA中使用for循环一定浪费资源吗?
渐渐地,发现自己已经习惯于发现细节,喜欢打破常规,真的非常喜欢这种feel. 相信很多人在书上或者博文上都有提出“在FPGA中使用for语句是很占用资源的”的观点,特权同学也不例外.那么,这种观点正确 ...
- [ci] jenkins的Timestamper插件-让日志显示时间
jenkins的Timestamper插件-让jenkins console带时间戳 安装插件 配置pipline,使用timestamp - 官网有说怎么用: 即用timestamps{} 包裹所有 ...
- [k8s]elk架构设计-k8s集群里搭建
elasticsearch和mysql的对比 https://blog.csdn.net/qq_21383435/article/details/79323383 Mapping ~ Schema m ...
- [sh]ls -F一种非常有用的ls格式
ls -F一种非常有用的ls格式 tz/y/yupeng > ls -F#q# News/ doc/ images/ mbox ...
- Django:Django Rest Framework
Django Rest Framework 一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称 ...
- 428. Pow(x, n)【medium】
Implement pow(x, n). Notice You don't need to care about the precision of your answer, it's acceptab ...
- 服务器搭建1 安装mysql数据库
一,安装mysql-service (1)检查系统中是否已经安装mysql 在终端里面输入 sudo netstat -tap | grep mysql 若没有反映,没有显示已安装结果,则没有安装.若 ...