如何使与Swing动画? [英] How to make an animation with Swing?

查看:205
本文介绍了如何使与Swing动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个JApplet的,结果被套牢了动画的问题。

I am making a JApplet and got stuck with a animation problem.

下面是我的code:

		this.sprite.setBounds(0,0,20,17);
		this.sprite.setIcon(this.rangerDown);
		for(int i = 0; i< 16;i++)
		{
			this.sprite.repaint();
			this.sprite.setLocation(this.sprite.getX(), this.sprite.getY()+10);
			try{
				Thread.currentThread().sleep(100);
			}catch(InterruptedException e){
			}
		}

通过这一点,有没有动画:在循环过程中没有任何反应,重绘()方法似乎曾经的精灵停止移动以便只

With this, there is no animation : nothing happens during the loop, the repaint() method seems to only act once the sprite stopped moving.

我想只使用摆动对于这一点,如何进行任何想法?

I would like to use only Swing for this, any ideas of how to proceed ?

感谢您的阅读。

推荐答案

您应该使用 javax.swing.Timer中的来执行,而不是线程休眠动画。这里是一个很好的链接让你去:的http:// java的.sun.com /文档/书籍/教程/ uiswing /其它/ timer.html

You should use a javax.swing.Timer to perform the animation rather than Thread sleeps. Here is a good link to get you going: http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html

此外,我强烈建议买这本书巨富客户端 - 如果你去的网站也可以下载所有这个例子code是免费的。例如,第12章:动画基础有一些伟大的例子,如MovingButton演示计时器使用。

Also I highly recommend buying the book Filthy Rich Clients -- if you go to the website you can also download all the example code for free. For example, Chapter 12: Animation Fundamentals has some great examples, such as MovingButton that demonstrates the Timer usage.

这篇关于如何使与Swing动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆