animation code in J2ME - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

animation code in J2ME

hi there i am new to J2ME and would like to know how to create an animation in J2ME? i have 5 images and would like to traverse then to achieve the animation.. i know i need an array and thread but i'm not too sure on how to implement it.. can someone enlighten me? :D

this is what i have done:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;

class Explosion implements Runnable
private Thread thread;
private int height, width;
private int y, x;
private GameCanvas canvas;
private Image imgCollection[]= new Image[4], bomb1, bomb2, bomb3, bomb4, bomb5;
private int imageNum = 0;

public Explosion(GameCanvas c){
canvas = c;
x=(canvas.getWidth()/12); //mid-way x
System.out.println("width: " + x);
y=(canvas.getHeight()*2/7)-2; //mid-way y
System.out.println("height: " + y);

bomb1 = null;
bomb2 = null;
bomb3 = null;
bomb4 = null;
bomb5 = null;

try {
bomb1 = Image.createImage("/bomb1.png");
bomb2 = Image.createImage("/bomb2.png");
bomb3 = Image.createImage("/bomb3.png");
bomb4 = Image.createImage("/bomb4.png");
bomb5 = Image.createImage("/bomb5.png");
} catch(IOException e){

try {
imgCollection[0] = bomb1;
imgCollection[1] = bomb2;
imgCollection[2] = bomb3;
imgCollection[3] = bomb4;
imgCollection[4] = bomb5;
} catch(IOException e){

public void startThread(){
Thread t = new Thread(this);

public void run() {
while(true) {
try {
if(imageNum > 7){
imageNum = 0;
} catch(Exception e){}


public void paint(Graphics g){
g.drawImage(imgCollection[imageNum], canvas.getWidth()/6,canvas.getHeight()*2/7+5,Graphics.TOP|Graphics.HCENTER);

is this correct? i get a exception is never thrown in body of corresponding try statement
} catch(IOException e){ :confused:
Sign In or Register to comment.