JAVA中的动画移动的JLabel每0.5秒 [英] Java move jlabel in animation every 0.5 second
问题描述
我想简单的动画设置位置每0.5秒,但它没有在循环结束动画只设置位置。
INT X = 1;结果
INT Y = 1;
而(X小于100){jLabel1.setLocation(X,Y);X = X + 10;
Y = Y + 10;
尝试{了Thread.sleep(500);}赶上(InterruptedException的E){}}
我试图用绘画动画Thread.sleep代码()和它的工作,这是正确的,但动画的unfortanly是不是选项我,我需要移动的JLabel各地框架至极具有里面人物的图片。
有人可以请帮我解决这个问题。
我曾尝试与这两相同的结果。
jLabel1.setBounds(X,Y,jLabel1.WIDTH,jLabel1.HEIGHT); //不工作
jLabel1.move(X,Y); //不工作
而不是使用的 Java的定时器尝试的摇摆定时器是比较适合的Swing应用程序。
请看看如何使用Swing计时器
查找样本code <一个href=\"http://stackoverflow.com/questions/23701688/how-to-fix-animation-lags-in-java/23701990#23701990\">How修复动画Java的滞后?
I want simple animation to set location every 0.5 second but it doesnt animate only set location at the end of the loop.
int x=1;
int y=1;
while(x<100){
jLabel1.setLocation(x, y);
x=x+10;
y=y+10;
try{Thread.sleep(500);}catch(InterruptedException e){}
}
I have tried drawing animation with thread.sleep() and it worked, it was animated correctly but unfortanly that is not option for me as i need to move jlabel around frame wich has figure picture inside it. Can someone pls help me with this problem.
i have tried with this two same result
jLabel1.setBounds(x, y, jLabel1.WIDTH,jLabel1.HEIGHT); //not working
jLabel1.move(x,y); //not working
Instead of using Java Timer try with Swing Timer that is more suitable for Swing application.
Please have a look at How to Use Swing Timers
Find a sample code How to fix animation lags in Java?
这篇关于JAVA中的动画移动的JLabel每0.5秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!