java 窗口中的动态效果

通过继承 JPanel 类和实现 Runnable 类,重写 paint(Graphics g) 和 run() 方法

来完成动态功能的:

class DrawPanel extends JPanel implements Runnable{

    public void paint(Graphics g) {
        
        super.paint(g);
        //ToDo    
    }
    public void run(){
        
        while(true){    
            this.repaint();
        }
    }    
}


直接实例化使用:

        
    Container ct = this.getContentPane();
    DrawPanel dp = new DrawPanel();
    ct.add(dp);
        
    Thread t = new Thread(dp);
    t.start();

 

posted @ 2013-02-25 23:13  LaoQuans  阅读(394)  评论(0编辑  收藏  举报