<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 如何制作動(dòng)畫(huà)程序

如何制作動(dòng)畫(huà)程序

作者: 時(shí)間:2012-05-07 來(lái)源:網(wǎng)絡(luò ) 收藏

360截圖20120507112220625.jpg

Table1

Timer

在Timer類(lèi)中主要使用下面的方法。

•voidschedule(TimerTasktask,Datedate)

•voidschedule(TimerTasktask,Datedate,longperiod)

•voidschedule(TimerTasktask,longdelay)

•voidschedule(TimerTasktask,longdelay,longperiod)

•voidcancel()

這些schedule方法用于設定任務(wù)及何時(shí)執行。若不設定第三個(gè)自變量period,在第二個(gè)自變量所指定的時(shí)間任務(wù)只執行一次。否則第二個(gè)自變量所指定的時(shí)間之后,任務(wù)會(huì )反復執行,自變量period是反復執行時(shí)的延時(shí)。另外,呼叫出cancel方法,則會(huì )結束計時(shí)器。

TimerTask

TimerTask是抽象類(lèi)。需要定義其子類(lèi)。在所繼承的類(lèi)中必須重載抽象方法run(),必須根據計時(shí)器的schedule定義具體的操作。

在TimerTask類(lèi)中主要使用如下的方法。

•abstractvoidrun()

•voidcancel()

按照Timer類(lèi)中所設定的schedule執行run()方法。用cancel()方法能夠結束任務(wù)。

現在來(lái)看看用線(xiàn)程實(shí)現的圓球運動(dòng)的--在這里我們也可以使用計時(shí)器來(lái)實(shí)現。如下所示:(ex.5)

importjavax.microedition.lcdui.Display;

importjavax.microedition.midlet.*;

/**

*球飛出去的實(shí)例計時(shí)器版

*/

publicclassTimerMovingBallextendsMIDlet{

privateDisplaydisplay;

privateTimerMovingBallCanvascanvas;

/**

*構造函數

*/

publicTimerMovingBall(){

display=Display.getDisplay(this);

canvas=newTimerMovingBallCanvas();

}

/**

*運行時(shí)的處理

*/

protectedvoidstartApp()throwsMIDletStateChangeException{

display.setCurrent(canvas);

}

protectedvoidpauseApp(){}

protectedvoiddestroyApp(booleanarg0)throwsMIDletStateChangeException{}

}

importjava.util.*;

importjavax.microedition.lcdui.*;

/**

*球飛出去的實(shí)例的canvas。

*/

publicclassTimerMovingBallCanvasextendsCanvas{

privateintx;//球的x坐標

privateImageimg;

privateTimertimer;

privateTimerTasktask;

/**

*構造函數

*/

publicTimerMovingBallCanvas(){

//讀取畫(huà)像

try{

img=Image.createImage(/back.PNG);

}catch(Exceptione){

e.printStackTrace();

}

//Timer,TimerTask的設定

timer=newTimer();

task=newTimerMovingBallTask(this);

timer.schedule(task,100,100);

//從第101毫秒開(kāi)始在每100毫秒運行任務(wù)

}

/**

*描繪方法

*/

protectedvoidpaint(Graphicsg){

g.drawImage(img,0,0,Graphics.LEFT|Graphics.TOP);

//表示球

g.setColor(255,0,0);

g.drawString(“withTimer”,0,0,Graphics.TOP|Graphics.LEFT);

g.fillArc(x,50,40,40,0,360);

}

/**

*能夠變化球的X坐標

*/

publicvoidincrement(){

x+=3;

}

}

/**

*計時(shí)器任務(wù)根據計時(shí)器所設定的時(shí)間表,運行run()方法。

*/

classTimerMovingBallTaskextendsTimerTask{

privateTimerMovingBallCanvascanvas;

/**

*構造函數

*/

publicTimerMovingBallTask(TimerMovingBallCanvascanvas){

this.canvas=canvas;

}

/**

*呼叫計時(shí)器時(shí)所進(jìn)行的處理

*/

publicvoidrun(){

canvas.increment();

canvas.repaint();

}

}

ex.5

TimerMovingCanvas類(lèi)的構造函數中進(jìn)行下面的計時(shí)器設定。

//Timer,TimerTask的設定

timer=newTimer();

task=newTimerMovingBallTask(this);

timer.schedule(task,100,100);//從第101毫秒開(kāi)始在每100毫秒運行任務(wù)

在TimerMovingBallTask中,從TimerTask繼承的run()被調用,X坐標的遞增使得球運動(dòng)起來(lái)。這樣有規律地使X坐標遞增,就使得圓球在畫(huà)面上從左到右移動(dòng)。(圖2)。

publicvoidrun(){

canvas.increment();

canvas.repaint();

}

2

■雙緩沖

一旦進(jìn)行動(dòng)畫(huà)就要頻繁地反復操作描繪處理,畫(huà)面處理中可能會(huì )突然發(fā)生屏幕閃爍。為了能夠控制屏幕的閃爍,一般會(huì )使用雙緩沖的手法。用雙緩沖存儲器并不是直接在畫(huà)面上進(jìn)行描繪,而是在被稱(chēng)為屏幕外畫(huà)像的虛擬畫(huà)像上描繪全部之后,由于是表示畫(huà)面,所以能控制屏幕的閃爍。(圖3)

Figure3

根據手機機種的不同,事先將Canvas類(lèi)與雙緩沖存儲器相對應的情況也是有的。換言之,即使實(shí)現方?jīng)]有明確地定義雙緩沖存儲器,則在用雙緩沖存儲器的機制進(jìn)行描繪的情況下,沒(méi)必要特別關(guān)心閃爍的解決方案,但是要在不同的機型上運行。N800的機型已經(jīng)能適應此雙緩沖存儲器。為此,開(kāi)發(fā)N800應用的時(shí)候,有時(shí)會(huì )有必要在這闡述雙緩沖存儲器的處理。此時(shí),應該知道終端是否適應雙緩沖存儲器、以及是否有必要分開(kāi)處理。



評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>