import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
class pro0210 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;
int gun;
public static void main(String[] args){
Frame f=new pro0210();
f.setTitle("
pro0210");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.show();
}
pro0210() {
addWindowListener(new stopwin());
t=0;
s=1;
dx=1;
gun=5;
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);
}
g.setColor(Color.green);
g.fillRect(100+50*gun,600,25,25);
}
public void update(Graphics g) {
paint(g);
}
public void run() {
int mode;
int minx,maxx;
int dg;
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;
}
dg=1;
if (Math.random()>0.5)dg=-1;
gun=gun+dg;
if (gun<1)gun=1;
if (gun>10)gun=10;
repaint();
try{th.sleep(1000);} catch(InterruptedException e) { }
t=t+1;
if (t>30)mode=100;
}
}
}
最終更新:2010年09月19日 21:53