国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

使用Timer制作動畫效果

2019-11-18 16:02:48
字體:
供稿:網(wǎng)友

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

public class TimerDemo extends MIDlet {

  Display    display;
  StarField  field = new StarField();
  FieldMover mover = new FieldMover();
  Timer      timer = new Timer();

  public TimerDemo() {
    display = Display.getDisplay( this );
  }

  PRotected void destroyApp( boolean unconditional ) { }

  protected void startApp() {
    display.setCurrent( field );
    timer.schedule( mover, 100, 100 );
  }

  protected void pauseApp() { }

  public void exit(){
    timer.cancel(); // stop scrolling
    destroyApp( true );
    notifyDestroyed();
  }

class FieldMover extends TimerTask {
  public void run(){
    field.scroll();
  }
}

class StarField extends Canvas {
  int        height;
  int        width;
  int[]      stars;
  Random     generator = new Random();
  boolean    painting = false;

  public StarField(){
    height      = getHeight();
    width       = getWidth();
    stars       = new int[ height ];

    forint i = 0; i < height; ++i ){
      stars[i] = -1;
    }
  }

  public void scroll() {
    if( painting ) return;

    forint i = height-1; i > 0; --i ){

      stars[i] = stars[i-1];
    }

    stars[0] = ( generator.nextInt() % ( 3 * width ) ) / 2;
    if( stars[0] >= width ){
      stars[0] = -1;
    }

    repaint();
  }

  protected void paint( Graphics g ){
    painting = true;

    g.setColor( 0, 0, 0 );
    g.fillRect( 0, 0, width, height );

    g.setColor( 255, 255, 255 );

    forint y = 0; y < height; ++y ){
      int x = stars[y];
      if( x == -1 ) continue;

      g.drawLine( x, y, x, y );
    }

    painting = false;
  }

  protected void keyPressed( int keyCode ){
    exit();
  }
}
}

使用Timer制作動畫效果 

(出處:http://m.survivalescaperooms.com)



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 关岭| 汉川市| 万安县| 永春县| 洞口县| 阜阳市| 黄梅县| 磴口县| 合阳县| 大悟县| 沾益县| 通河县| 新余市| 湖北省| 怀集县| 虞城县| 霍山县| 雷波县| 水富县| 鹤山市| 沅陵县| 青冈县| 饶河县| 惠来县| 马关县| 杭锦旗| 开江县| 鹿泉市| 永新县| 广丰县| 石城县| 宿松县| 藁城市| 裕民县| 三河市| 巫溪县| 新绛县| 岳普湖县| 湖南省| 革吉县| 安国市|