java线程 马士兵_java线程问题(马士兵tank里的)

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()里。他这样写实什么思想呢?麻烦知道的高手教我一下(他的代码是我注释掉的)。详解.....

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值