import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
class game0104 extends Frame implements Runnable{
Frame f;
Thread th;
int gun;
int dg;
public static void main(String[] args){
Frame f=new game0104();
f.setTitle("game0104");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.show();
}
game0104() {
addWindowListener(new stopwin());
setLayout(new FlowLayout());
Button bu = new Button( "ボタン" );
bu.addActionListener(new MyListener());
add(bu, BorderLayout.NORTH );
setVisible( true );
gun=250;
dg=10;
th=new Thread(this);
th.start();
}
class MyListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
dg=-dg;
}
}
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:45