Home J2me J2ME Frame Animation2



J2ME Frame Animation2
Posted on: December 2, 2008 at 12:00 AM
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

Related Tags for J2ME Frame Animation2:
ciovilockthisblocksetframeexampleramexamlockseilmanualblocksmaninasmtresalllocmerateratescreatingsamexaxampsatkisllivmplpreeaandarstrsassamssamthstatiframmanupleplprndo


More Tutorials from this section

Ask Questions?    Discuss: J2ME Frame Animation2   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.