<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    讓變化成為計(jì)劃的一部分

    歡迎大家探討本Blog涉及的所有軟件課題。我的Google Talk ID:zhengyun(at)gmail.com。

    我最希望軟件帶給用戶的感受是:美好的體驗(yàn)、舒適感、簡(jiǎn)約、干凈...

    posts - 32, comments - 8, trackbacks - 0, articles - 0
      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    請(qǐng)參考java.util.TimerTask.

    TimerTask is something like Timer in VisualBasic. You can sepcify a time period in milliseconds

    for your requirement"一幅LOGO顯示完以后,幾秒種自動(dòng)顯示下一幅LOGO".
    Here is an sample code.

    public void testTimer() {
    MyTimerTask myTimerTask 
    = new MyTimerTask();
    Timer timer 
    = new Timer();
    timer.schedule(myTimerTask, 
    500010000); //wait for 5 seconds and then call the function every 

    10 seconds
    }


    class MyTimerTask extends TimerTask {
    public void run() {
    //This method will be called every 10 Seconds

    Image im 
    = Image.createImage(imageData, 0, imageData.length);
    if(im == null)
    System.out.println(
    "NULL IMAGE");
    System.out.println(
    "The Size of the Byte Array is:" +imageData);
    if(frm.size() > 0)
    for(int i = 0; i < frm.size(); i++)
    frm.delete(i);
    frm.append(im);
    disp.setCurrent(frm);

    }

    }


     

    另外,對(duì)于你所說的是不是應(yīng)該叫做SplashScreen,那么國(guó)外曾經(jīng)有人給出這么一個(gè)例子,雖然不是周期性地顯示一張又一張的圖片,而是利用TimerTask周期性地repaint畫布,畫出一種Splash Screen的感覺,你可以參考:

    import java.util.*;

    import javax.microedition.lcdui.*;

    public class WaitCanvas
    extends Canvas {
    private int mCount, mMaximum;
    private int mInterval;

    private int mWidth, mHeight, mX, mY, mRadius;
    private String mMessage;

    public WaitCanvas() {
    mCount 
    = 0;
    mMaximum 
    = 36;
    mInterval 
    = 100;

    mWidth 
    = getWidth();
    mHeight 
    = getHeight();

    // Calculate the radius.
    int halfWidth = (mWidth - mRadius) / 2;
    int halfHeight = (mHeight - mRadius) / 2;
    mRadius 
    = Math.min(halfWidth, halfHeight);

    // Calculate the location.
    mX = halfWidth - mRadius / 2;
    mY 
    = halfHeight - mRadius / 2;

    // Create a Timer to update the display.
    TimerTask task = new TimerTask() {
    public void run() {
    mCount 
    = (mCount + 1% mMaximum;
    repaint();
    }

    }
    ;
    Timer timer 
    = new Timer();
    timer.schedule(task, 
    0, mInterval);
    }


    public void setMessage(String s) {
    mMessage 
    = s;
    repaint();
    }


    public void paint(Graphics g) {
    int theta = -(mCount * 180 / mMaximum);


    // Clear the whole screen.
    g.setColor(255255255);
    g.fillRect(
    00, mWidth, mHeight);

    // Now draw the pinwheel.
    g.setColor(000);

    g.drawArc(mX, mY, mRadius, mRadius, 
    0360);

    g.fillArc(mX, mY, mRadius, mRadius, theta 
    + 2020);
    //g.fillArc(mX, mY, mRadius, mRadius, theta + 60, 60);
    //g.fillArc(mX, mY, mRadius, mRadius, theta + 90, 90);
    //g.fillArc(mX, mY, mRadius, mRadius, theta + 120, 120);

    // Draw the message, if there is a message.
    if (mMessage != null)
    g.drawString(mMessage, mWidth 
    / 2, mHeight,
    Graphics.BOTTOM 
    | Graphics.HCENTER);
    }

    }



    上面那個(gè)是利用TimerTask自動(dòng)定時(shí)填充圖形來展示Splash Screen的,那么下面這個(gè)就是顯示圖片來Splash Screen了:


     

    import java.util.*;
    import javax.microedition.lcdui.*;

    public class Splash extends Canvas {

    private Display display;
    private Displayable next;
    private Timer timer=new Timer();

    public Splash (Display display,Displayable next) {
    this.display=display;
    this.next=next;
    display.setCurrent(
    this);
    }


    protected void showNotify () {
    timer.schedule( 
    new TimerTask () public void run() {
    displayNext(); }
    }
    ,8000);
    }


    protected void hideNotify() {
    timer.cancel();
    }


    protected void keyPressed (int keycode) {
    displayNext();
    }


    protected void pointerPressed (int x, int y) {
    displayNext();
    }


    private void displayNext() {
    display.setCurrent(next);
    }
     

    protected void paint (Graphics g) {
    int height=this.getHeight();
    int width=this.getWidth();

    // fill background as white
    g.setColor(0xFFFFFF);
    g.fillRect(
    0,0,width,height);

    Image logo
    =null;
    try {
    logo
    =Image.createImage("/images/logo.png");
    }
     catch (Exception ignore) {}

    g.drawImage(logo,width
    /2,height/2,g.HCENTER|g.VCENTER);
    }


    }
     

    here
    's the calling method in your midlet(it passes the Display and current Displayable):

    /**
    * This shows the splash
    */


    private void showSplash () {
    new Splash (display,MenuList); 
    }



    還有一種辦法是利用currentTimeMillis。
    無非就是利用System.currentTimeMillis()+2000先行計(jì)算出什么時(shí)間該顯示
    后一幅圖片了,如果靠while循環(huán)不斷檢測(cè)發(fā)現(xiàn)時(shí)間到了,就換那張圖片。
    private boolean showImage;


    void someMethod()
    {
    long time = System.currentTimeMillis()+2000;

    showImage 
    = true;
    while(System.currentTimeMillis()<time)
    {
    repaint();
    serviceRepaints();
    }

    showImage 
    = false;
    }


    public void paint()
    {

    if(showImage)
    g.drawImage(img,offsetX,MAX_Y
    /2,g.LEFT|g.VCENTER);
    }

    efei說:
    “你要做的無非就是一個(gè)延時(shí),過一定時(shí)間就換一幅圖片。至于怎么來判斷這個(gè)延時(shí),方法多種多樣,用線程,用TimerTask,用System.currentTimeMillis(),基本上都一樣

    個(gè)人比較傾向于使用線程作為固定的時(shí)鐘脈沖來驅(qū)動(dòng)游戲。

    對(duì)于System.currentTimeMillis(),我只能告訴你兩點(diǎn),一是它的作用是取得當(dāng)前時(shí)間,二呢,用這個(gè)方法如果只是簡(jiǎn)單比較時(shí)間,那么如果中斷游戲,過一段時(shí)間再恢復(fù),就會(huì)存在問題。

    主站蜘蛛池模板: 亚洲精品视频在线观看免费| 青青操视频在线免费观看| 亚洲美女视频免费| 久久久综合亚洲色一区二区三区 | 十九岁在线观看免费完整版电影| 亚洲第一黄片大全| 一本久久免费视频| 亚洲综合色区在线观看| 一区二区三区免费看| 亚洲人成色77777在线观看大| 一个人看的hd免费视频| 国产亚洲一区二区三区在线观看| 中国性猛交xxxxx免费看| 久久亚洲一区二区| 男女超爽刺激视频免费播放| 亚洲最大的成人网| 免费中文字幕不卡视频| 国产精品无码免费专区午夜| 国产亚洲精品a在线无码| 13一14周岁毛片免费| 国产成人精品日本亚洲专 | 亚洲成a人无码av波多野按摩| 十八禁的黄污污免费网站| 亚洲精品乱码久久久久久久久久久久 | 亚洲成a人片在线观看无码| 最近中文字幕免费mv在线视频| 久久精品国产亚洲av麻豆图片| 在线观看亚洲免费| 中文字幕永久免费| 亚洲国产理论片在线播放| 免费一级肉体全黄毛片| 日本免费一区二区三区| 亚洲国产欧美国产综合一区| 亚洲国产香蕉人人爽成AV片久久| 久久精品免费观看国产| 亚洲精品动漫免费二区| 国产AV无码专区亚洲精品| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 青娱乐免费在线视频| 成人一级免费视频| 亚洲人成网站18禁止久久影院|