zoukankan      html  css  js  c++  java
  • 用Java制作动画效果

    用Java画动画很简单,让一个线程自己定时调用自己即可,记得要设置一个退出(结束)条件。

    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();
        }
    }

    运行结果:

    数字不停增长

  • 相关阅读:
    线段树优化dp(elect选择)
    gdb调试
    无参装饰器
    3.23作业
    3.22周末作业
    函数对象与闭包函数
    3.20作业
    3.19作业
    名称空间与作用域
    函数参数的使用
  • 原文地址:https://www.cnblogs.com/bjzhanghao/p/694268.html
Copyright © 2011-2022 走看看