国产探花免费观看_亚洲丰满少妇自慰呻吟_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://www.survivalescaperooms.com)



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 洛浦县| 泰安市| 晋宁县| 苏州市| 富源县| 兰考县| 南召县| 吉首市| 闽清县| 泸水县| 莱州市| 腾冲县| 东明县| 子长县| 宁波市| 彭阳县| 凤台县| 文登市| 宁乡县| 弥勒县| 玛曲县| 白银市| 盘锦市| 南陵县| 高碑店市| 远安县| 安远县| 澎湖县| 富宁县| 上高县| 黄陵县| 壶关县| 岱山县| 越西县| 平乡县| 永清县| 焉耆| 丰县| 建德市| 拜泉县| 铜鼓县|