乐文小说网

乐文小说网>Java语言入门 > 第8部分(第1页)

第8部分(第1页)

注意:这并没有消灭这个线程,但它停止了线程的执行。并且这个线程不能用t1。start()重新启动。在我们的例子里,我们从来不用显式地停止一个线程。我们只简单地让它执行完而已。很多复杂的线程例子将需要我们控制每一个线程。在这种情况下会使用到stop()函数。如果需要,你可以测试你的线程是否被激活。一个线程已经启动而且没有停止被认为是激活的。t1。isAlive()如果t1是激活的,这个函数将返回true。

7。2。7动画例子

下面是一个包含动画线程的applet例子:

importjava。awt。*;importjava。awt。image。ImageProducer;import

java。applet。Applet;

publicclassatest3extendsAppletimplementsRunnable{Imageimages'';

MediaTrackertracker;intindex=0;Threadanimator;

intmaxWidth;maxHeight;Ouroff…screenponentsfordoublebuffering。

ImageoffScrImage;GraphicsoffScrGC;

Canwepaintyes?booleanloaded=false;

Initializetheapplet。Setoursizeandloadtheimagespublicvoidinit()

'Setupourimagemonitortracker=newMediaTracker(this);

SetthesizeandwidthofourappletmaxWidth=100;maxHeight=100;

images=newImage'10';Setupthedouble…bufferandresizeourapplet

try{offScrImage=createImage(maxWidth;maxHeight);offScrGC=

offScrImage。getGraphics();offScrGC。setColor(Color。lightGray);

offScrGC。fillRect(0;0;maxWidth;maxHeight);

resize(maxWidth;maxHeight);}catch(Exceptione)

{e。printStackTrace();}

loadtheanimationimagesintoanarrayfor(inti=0;i=images。length){index=0;}}

Delayheresoanimationlooksnormaltry{animator。sleep(200);}catch

(InterruptedExceptione){}Drawthenextframerepaint();}}}

请勿开启浏览器阅读模式,否则将导致章节内容缺失及无法阅读下一章。

相邻推荐:闲巫在都市  元宝传奇  节妇的悠然生活  魅魔模拟器  荒界实录  穿越之正妻诱惑 02.25完结+1番外  游神传说之界王  黄帝内经实用手册  道君且慢  要说多少次,我不是人奸!  上古卷轴天际之子    产生物  天空大陆  众语皆悲  东北谜踪  娘亲V5父皇很欠抽  洪荒老祖已无敌  鬼夜  史上最拽的十个女人  

已完结热门小说推荐

最新标签