矩形类-内部类刷新

package cn.test.circle;

import java.awt.Graphics;

public class MyRectangle {

    private int x ;
    private int y ;
    private int w ;
    private int h ;
    public MyRectangle(int x, int y, int w, int h) {
        super();
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
        
        new MyRecThread().start();
    }
    
    public void drawMe(Graphics g){
        g.drawRect(x, y, w, h);
    }
    
    private class MyRecThread extends Thread{
        @Override
        public void run() {
            super.run();
            while(true){
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //不断改变属性值
                x = (int)(Math.random()*100);
                y = (int)(Math.random()*100);
                w = (int)(Math.random()*100);
                h = (int)(Math.random()*100);
                
                System.out.println("圆的内部在刷新坐标"+x+"--"+y+"---"+w+"---"+h);
            }
        }
    }
    
}

 

posted @ 2018-01-17 13:59  yoyo198212  阅读(107)  评论(0编辑  收藏  举报