对于线程的一些理解

#isubb#package untitled1; import javax.microedition.lcdui.*; public class tetriscanvasdemo extends canvas implements runnable{ int drawx,drawy; image source; image copy; tetriscanvasdemo() { drawx=this.getwidth()/2; drawy=0; copy=image.createimage(this.getwidth(),this.getheight()); } protected void paint(graphics g) { graphics offscreen=copy.getgraphics(); offscreen.setcolor(255,255,255); offscreen.fillrect(0,0,this.getwidth(),this.getheight()); offscreen.setcolor(0,0,0); offscreen.fillrect(drawx,drawy,10,10); g.drawimage(copy,0,0,graphics.left |graphics.top); } public void run() { while(true) { this.down(); repaint(); try { thread.sleep(50);; } catch(interruptedexception e) { system.out.println("sleep error:"+e.getmessage()); } } } public void start() { thread t=new thread(this); t.start(); } protected void down() { if(drawy { drawy=drawy+1; } else { drawy=0; } } } [b] 在这个类中,如果没有implemnt runable那就是一般的canvas界面,执行完构造函数再paint函数显示就完了。加了runable,在start里,[color=#ff0000]thread t=new thread(this)就将此canvas定义为一个线程了,[/color]t.start()启动线程,在run里就可以写这个线程中做些什么了。 [/b]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值