import java.awt.*;
import java.awt.event.*;
class game0203 extends Frame implements Runnable{
int gun;
int mode;
Image img;
public static void main(String [] args) {
Frame f=new game0203();
f.setTitle("game0203");
f.setSize(700,700);
f.setBackground(Color.white);
f.setVisible(true);
}
game0203(){
img = Toolkit.getDefaultToolkit().getImage("images.jpg");
Thread th=new Thread(this);
th.start();
addWindowListener(new stopwin());
}
class stopwin extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}
public void run(){
int t;
int dg;
t=1;
mode=0;
while(mode<100){
dg=1;
if (Math.random()>0.5)dg=-1;
gun=gun+dg;
if (gun>10)gun=10;
if (gun<1)gun=1;
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;
if (t>100)mode=200;
}
repaint();
}
public void paint(Graphics g){
if (mode<100){
g.setColor(Color.white);
g.fillRect(0,0,700,700);
g.setColor(Color.black);
g.fillRect(100+50*gun,550,50,50);
}
if (mode==200){
g.drawImage(img,0,0,700,700,this);
}
if (mode==300){
g.setColor(Color.black);
g.drawString("game over",300,300);
}
}
}
最終更新:2011年02月03日 15:04