import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
class pro0209 extends Frame implements Runnable{
Frame f;
Thread th;
int s,m,n,t;
int x[]=
new int[16];
int y[]=new int[16];
int dx;
public static void main(String[] args){
Frame f=new pro0209();
f.setTitle("
pro0209");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.show();
}
pro0209() {
addWindowListener(new stopwin());
t=0;
s=1;
dx=1;
for (m=8;m<11;m++){
for (n=3;n<8;n++){
x[s]=n;
y[s]=m;
s=s+1;
}
}
th=new Thread(this);
th.start();
}
class stopwin extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}
public void paint( Graphics g ) {
g.setColor(Color.yellow);
g.fillRect(0,0,700,700);
g.setColor(Color.red);
for (s=1;s<16;s++){
g.fillRect(
100+50*x[s],600-50*y[s],10,10);
}
}
public void update(Graphics g) {
paint(g);
}
public void run() {
int mode;
int minx,maxx;
mode=0;
while(mode<50){
minx=
999;
for (s=1;s<16;s++){
if (x[s]<minx)minx=x[s];
}
maxx=-999;
for (s=1;s<16;s++){
if (x[s]>maxx)maxx=x[s];
}
if (maxx==10)dx=-1;
if (minx==1)dx=1;
for (s=1;s<16;s++){
if (maxx==10)y[s]=y[s]-1;
if (minx==1)y[s]=y[s]-1;
x[s]=x[s]+dx;
}
repaint();
try{th.sleep(1000);} catch(InterruptedException e) { }
t=t+1;
if (t>30)mode=100;
}
}
}
最終更新:2010年09月19日 21:35