JAVA认证 百分网手机站

J2ME在移动设备上实现动画程序方法(2)

时间:2018-04-10 20:56:59 JAVA认证 我要投稿

J2ME在移动设备上实现动画程序方法

  public Display getDisplay(){; return display; };

  // Initialize things by creating the canvas and then

  // creating a series of birds that are moved to

  // random locations on the canvas and attached to

  // a timer for scheduling.

  protected void initMIDlet(){;

  try {;

  AnimatedCanvas c = new

  AnimatedCanvas( getDisplay() );

  Image[] images =loadFrames( "/images/bird", BIRD_FRAMES );

  int w = c.getWidth();

  int h = c.getHeight();

  birds = new AnimatedImage[ NUM_BIRDS ];

  for( int i = 0; i < NUM_BIRDS; i ){;

  AnimatedImage b = new

  AnimatedImage( c, images );

  birds = b;

  b.move( genRandom( w ), genRandom( h ) );

  c.add( b );

  timer.schedule( b, genRandom( 1000 ),genRandom( 400 ) );

  };

  c.addCommand( exitCommand );

  c.setCommandListener( this );

  getDisplay().setCurrent( c );

  };

  catch( IOException e ){;

  System.out.println( "Could not load images" );

  exitMIDlet();

  };

  };

  // Load the bird animation, which is stored as a

  // series of PNG files in the MIDlet suite.

  private Image[] loadFrames( String name, int frames )

  throws IOException {;

  Image[] images = new Image[frames];

  for( int i = 0; i < frames; i ){;

  images = Image.createImage( name i ".png" );

  };

  return images;

  };

  protected void pauseApp(){; };

  protected void startApp()

  throws MIDletStateChangeException {;

  if( display == null ){;

  display = Display.getDisplay( this );

  initMIDlet();

  };

  };

  };

  七帧图片的动画,你可以看到一个拍着翅膀的小鸟。MIDlet显示了5只小鸟,小鸟的位置和刷新速度是随机的。你可以用一些其他的办法来改进这个程序,但这个程序也应该足够能让你上手了。

【J2ME在移动设备上实现动画程序方法】相关文章:

1.堆的javascript实现方法

2.动画比例的设计方法

3.PPT动画设置方法

4.Java中goto实现方法

5.实现硬盘raid的方法

6.土地定级的程序与方法

7.绩效考核中的程序公正及实现

8.实现鼠标画图的Java程序