该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.awt.*;
import java.awt.event.*;
public class TankClient 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);
x += x;
y += y;
}
public void lauchFrame() {
this.setLocation(400, 300);
this.setSize(800, 600);
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
this.setResizable(false);
this.setBackground(Color.green);
new Thread(new PaintThread()).start();//请问这句为什么不能放在main方法里?放在main方法里就会报错??
}
public static void main(String args[]){
TankClient tc = new TankClient();
tc.lauchFrame();
//PaintThread pt = new PaintThread();
//Thread t = new Thread(pt);
}
private class PaintThread implements Runnable{
public void run() {
while(true){
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}