Home J2me J2ME Frame Animation2
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

J2ME Frame Animation2

Advertisement
This example illustrates same as in the previous example, but here we are creating four blocks and set five frame manually.

J2ME Frame Animation2

     

This example illustrates same as in the previous example, but here we are creating four blocks and set five frame manually. The whole example shows you to create the frame and blocks. In this example user can set the frame and blocks manually on the run time. In the source code we extend the FrameAnimation class, which is also used in the previous application. For the movement of the blocks we create the moveAllBlocks() function, the source code is as follows:

 

 

 

 

 

public synchronized void moveAllBlocks(){
  for (int i = 0, count = blocks.length; i < count; i++){
  Block block = blocks[i];
  repaint(block.x, block.y, SIZE, SIZE);
  blocks[i].move();
  repaint(block.x, block.y, SIZE, SIZE);
  }
}

The Application is as follows:

 

FrameAnimation2.java

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

public class FrameAnimation2 extends FrameAnimation {
  protected FrameAnimation.AnimationCanvas createAnimationCanvas(){
  return new AnimationCanvas2();
  }
  
  class AnimationCanvas2 extends FrameAnimation.AnimationCanvas{
  protected void paint(Graphics g){
  int clipX = g.getClipX();
  int clipY = g.getClipY();
  int clipWidth = g.getClipWidth();
  int clipHeight = g.getClipHeight();
  g.setColor(background);
  g.fillRect(clipX, clipY, clipWidth, clipHeight);
  g.setColor(foreground);
  synchronized (this){
  for (int i = 0, count = blocks.length; i < count; i++) {
  g.fillRect(blocks[i].x, blocks[i].y, SIZE, SIZE);
  }
  }
  }
  public synchronized void moveAllBlocks(){
  for (int i = 0, count = blocks.length; i < count; i++){
  Block block = blocks[i];
  repaint(block.x, block.y, SIZE, SIZE);
  blocks[i].move();
  repaint(block.x, block.y, SIZE, SIZE);
  }
  }
  }
} 

 

Download Source Code

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 2, 2008

Ask Questions?    Discuss: J2ME Frame Animation2   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com