六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 55|回复: 0

(转自八进制)用Java制作动画效果

[复制链接]

升级  6%

13

主题

13

主题

13

主题

秀才

Rank: 2

积分
59
 楼主| 发表于 2013-2-3 11:16:29 | 显示全部楼层 |阅读模式
<div class="postText">原文地址http://www.cnblogs.com/bjzhanghao/archive/2007/03/30/694268.html
用Java画动画很简单,让一个线程自己定时调用自己即可,记得要设置一个退出(结束)条件。
 
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee;"><!---->import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class Animation {
    
final static int DELAY = 500;

    
public static void main(String[] args) {
        
final Display display = new Display();
        
final Shell shell = new Shell(display);
        shell.setLayout(
new FillLayout());
        
final Text text = new Text(shell, SWT.BORDER);
        text.setText(
"0");
        
new Runnable() {
            
public void run() {
                
if (shell.isDisposed())
                    
return;
                text.setText(
"" + (Integer.parseInt(text.getText()) + 1));
                Display.getDefault().timerExec(DELAY, 
this);
            }
        }.run();

        shell.pack();
        shell.open();
        
while (!shell.isDisposed()) {
            
if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表