importjava.awt.*;importjava.awt.event.*;publicclassTankClientextendsFrame{intx=30;inty=30;publicstaticvoidmain(String[]args){newTankClient().lanuch();}publicvoidlanuch(){...
import java.awt.*;
import java.awt.event.*;
public class TankClient extends Frame{
int x = 30;
int y = 30;
public static void main(String []args) {
new TankClient().lanuch();
}
public void lanuch() {
this.setLocation(100, 100);
setSize(800,600);
this.setBackground(Color.green);
this.setResizable(false);
setVisible(true);
this.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
//new Thread(new TankThread()).start();
while(true) {
repaint();
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void paint(Graphics g) {
Color c =g.getColor();
g.setColor(Color.red);
g.fillOval(x, y, 30, 30);
g.setColor(c);
y += 5;
}
/*private class TankThread implements Runnable {
public void run() {
while(true) {
repaint();
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}*/
}
视频里是起一个线程进行重画,我是直接放在lanuch()里。请问两者区别在哪,我的第一感觉就写在lanuch()里。他这样写实什么思想呢?麻烦知道的高手教我一下(他的代码是我注释掉的)。详解.....
展开