黑马程序员技术交流社区

标题: 自己学习编写的一个java线程动画代码 [打印本页]

作者: yedong313    时间: 2015-7-2 06:57
标题: 自己学习编写的一个java线程动画代码
import java.awt.*;
import java.awt.event.*;
public class Mutative {
        public static void main(String[]args){
                Mywin win=new Mywin();
                win.pack();
        }
}

class Mywin extends Frame implements Runnable{
        Button b=new Button("ok");
        int x=5;
        Thread thread=null;
        Mywin(){
                setBounds(100,100,200,200);
                setLayout(new FlowLayout());
                setVisible(true);
                add(b);
                b.setBackground(Color.green);
                addWindowListener(new WindowAdapter(){
                        public void windowClosing(WindowEvent e){
                                System.exit(0);
                        }
                });
                thread=new Thread(this);
                thread.start();
        }
        public void run(){
                while(true){
                        x=x+1;
                        if(x>100)
                                x=5;
                        b.setBounds(40, 40, x, x);
                        try{
                                thread.sleep(200);
                        }catch(InterruptedException e){
                                }
                }
        }
}
作者: yedong313    时间: 2015-7-2 07:01
动画效果是将一个绿颜色按钮在窗口中逐渐放大,有兴趣的可以粘贴代码试一试
作者: 430422    时间: 2015-7-2 07:29
大神啊,膜拜中。。。。。
作者: umbriel    时间: 2015-7-2 09:22
看起来挺不错哦!!
作者: 水壶vs兔子    时间: 2015-7-2 09:43
好奇,进来看看的,呵呵,觉得好神奇!
作者: 王文辉    时间: 2015-7-2 09:46
没研究过java动画
作者: tinibuzhi    时间: 2015-7-2 22:04
java动画,好神奇:lol




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2