#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]
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
对于一些画图的理解--箱线图
借用师地的论文来说一下任务
数据集 卷积 子序列 -
对于“前端canvas骚操作”的一些理解
canvas ,作为HTML5的「画布」,canvas强大的功能将一直伴随H5走下去。前端使用can
html5 canvas javascript css3 前端 -
OSPF的一些理解
OSPF特点
OSPF -
对于 “OWASP TOP 10” 的一些理解
最近几次电话面试,都比较悲剧,关于面试者比较关注的地方,总不能----------------------------
php html sql注入 json js代码