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( ...
随机推荐
- electron的通信
1.获取当前设备的屏幕可用区域的分辨率winW=electron.screen.getPrimaryDisplay().workAreaSize.widthwinH=electron.screen.g ...
- div设置contentEditable="true"作为文本编辑器,定位光标解决办法
function set_focus(el) { el = el[0]; // jquery 对象转dom对象 el.focus(); if ($.browser.msie) { ...
- vue实现前端导出excel表格
1.在src目录下创建一个文件(vendor)进入Blob.js和Export2Excel.js 2.npm install -S file-saver 用来生成文件的web应用程序 3.npm in ...
- 利用eclipse中的各种功能帮助你理解代码
@菜单栏下面,工具栏,有一对黄色的箭头按钮,一个指向左边,一个指向右边,快捷键是Alt+Left/Alt+Right 功能是跳转到你刚刚编辑过的地方 这里的Left/Right指的是左右方向键,可以方 ...
- QQ自动发送+@好友功能+tencent://功能
1.取出全部标题 D2007版本 procedure TForm1.Button1Click(Sender: TObject);var hCurrentWindow:HWnd; szText: a ...
- ref和out的使用与区别【转】
http://www.cnblogs.com/sjrhero/articles/1922902.html out的使用 ———————————————————————————————————————— ...
- JS parseInt 中08.09 被按照0处理(转)
<script type="text/javascript"> var aa=["01","02","03" ...
- 4款基于jquery的列表图标动画切换特效
网页中列表图标随处可见,特别是移动网页上,基本上的导航都采用了列表图标.今天给大家分享4款基于juqery的列表图标和关闭图标的动画切换特效.喜欢的网友赶紧收藏吧. 在线预览 源码下载 实现的代码 ...
- php爬虫实践
之前用nodejs的cheerio来做,不过nodejs的异步回掉太恶心了,受不了. 后来发现了php的htmlpagedom库,类似jquery的选择器语法,而且支持中文. 安装 composer ...
- java安全性的一种简单思路
关于接口安全性的考虑.这客户端在调用接口时,将acId授权码以加密的方式(可逆加密方式)传递过来, 服务端这边接收后进行解密,然后在服务器端这边的授权名单中进行匹配,判断该授权码是否被授权,从而判断第 ...