import java.awt.*;
import java.awt.event.*;
public class Tank extends Frame {
int x = 50, y = 50;
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(Color.RED);
g.fillOval(x,y,30,30);
g.setColor(c);
y += 5;
}
public void launchFrame() {
setSize(800, 600);
setLocation(200, 200);
setTitle("TankWar");
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setResizable(false);
setBackground(new Color(100,255,100));
setVisible(true);
new Thread(new PaintThread()).start();
}
public static void main(String[] args) {
Tank tc = new Tank();
tc.launchFrame();
}
private class PaintThread implements Runnable {
public void run() {
try {
while(true) {
repaint();
Thread.sleep(100);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
我在eclipse上面运行为什么那个红色原点一直闪烁。。 闪烁的很厉害 怎么样才能不让他闪烁呢? |
|