import java.awt.*;
class move1 extends Frame{
int locationX=20,locationY=20; //方块的其始坐标
Canvas mycanvas=new Canvas();
move1(){ //构造函数
this.add(mycanvas);
this.setSize(300,300);
this.setVisible(true);
}
public void paint(Graphics g){ //绘图并使之移动
g=mycanvas.getGraphics();
g.setColor(Color.black);
g.fillRect(locationX++,locationY++,10,10);
try
{
Thread.sleep(100);
}
catch(InterruptedException e){}
repaint();
}
public static void main (String[] args) {
new move1();
}
}