アットウィキロゴ

java0204

import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;

class game0204 extends Frame implements Runnable{

Frame f;
Thread th;
int gun;
int dg;

public static void main(String[] args){
Frame f=new game0204();
f.setTitle("game0204");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.show();
}

game0204() {
addWindowListener(new stopwin());

setLayout(new FlowLayout());
Button bu1 = new Button("migi");
bu1.addActionListener(new beck());
add(bu1);
bu1.setActionCommand("c1");

Button bu2 = new Button("hida");
bu2.addActionListener(new beck());
add(bu2);
bu2.setActionCommand("c2");


setVisible( true );
gun=250;
dg=10;
th=new Thread(this);
th.start();
}


class beck implements ActionListener {
public void actionPerformed(ActionEvent e) {
if ("c1".equals(e.getActionCommand()))dg=10; ;
if ("c2".equals(e.getActionCommand()))dg=-10;  
}
}


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);
gun=gun+dg;
g.setColor(Color.red);
g.fillRect(gun,350,10,10);

}

public void update(Graphics g) {
paint(g);
}

public void run() {
int t;
t=0; ;
while (t<200){
repaint();
try{th.sleep(100);} catch(InterruptedException e) { }
t=t+1;
}

}
}
最終更新:2011年02月03日 16:54