Code:
package animationMaker;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.m2g.SVGImage;
import javax.microedition.m2g.ScalableGraphics;
import javax.microedition.m2g.ScalableImage;
import javax.microedition.media.*;
import javax.microedition.rms.*;
import java.util.*;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.*;
import java.util.*;
import javax.microedition.rms.*;
import org.w3c.dom.Document;
import org.w3c.dom.svg.SVGSVGElement;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.m2g.ScalableGraphics;
import javax.microedition.m2g.ScalableImage;
/**
*
* @author Shiro
*/
public class EditChar extends Canvas implements CommandListener {
private mainMenuMidlet midlet;
private Display display;
private Command bkCmd, sltCmd, textCommand;
Form displayForm;
Form form;
ChoiceGroup sizeChoice;
ChoiceGroup AnimChoice;
private int x,y;
character characterOne;
character characterTwo;
private ScalableImage background;
private String text=" ";
private String fontSize = "";
private String fontColour = "";
private CanvasList cl;
private String addChoice="";
//ALICE
private Sprite alice; //Sprite: movement of individual graphic objects
private Image image;
private AliceThread aThread;
public EditChar(String title, mainMenuMidlet m, Display d, ScalableImage background, String text, int x, int y, String fontSize, String fontColour,character chracterOne1, character characterTwo1,String addChoice) {
this.x=x;
this.y= y;
characterOne=chracterOne1;
characterTwo=characterTwo1;
this.background= background;
midlet=m;
display= d;
this.text=text;
this.fontColour=fontColour;
this.fontSize=fontSize;
this.addChoice=addChoice;
System.out.println("add choice in edit char"+ addChoice);
System.out.println("edit char "+ characterOne.getCharacterHeadIndex());
bkCmd = new Command("Back", Command.EXIT, 2);
sltCmd = new Command("Done", Command.OK, 1);
addCommand(bkCmd);
addCommand(sltCmd);
setCommandListener(this);
setTitle(title);
//alice
try {
image = Image.createImage("/picture/Tortoise1.png");
} catch (IOException exception) {
exception.printStackTrace();
}
alice = new Sprite(image, 351/3, 126);
x = getWidth();
y = 50;
aThread = new AliceThread();
aThread.start();
}
class AliceThread extends Thread{
public void run(){
while (true) {
try{
sleep(100000);
}catch(InterruptedException ie) {
ie.printStackTrace();
}
x -= 20;
if(x <= 0 - image.getWidth())
x = getWidth();
repaint();
}
}
}
public void commandAction(Command c, Displayable d) {
}
public void paint(Graphics g) {
clearScreen(g);
form= getForm();
display.setCurrent(form);
g.setColor(0xFFFFFF);
//g.fillRect(60,100,getWidth(),getHeight());
}
Form getForm() {
if (form == null) {
System.out.println("HIHI");
form = new Form("Option");
sizeChoice = new ChoiceGroup("Character Size:", Choice.POPUP);
sizeChoice.append("Small", null);
sizeChoice.append("Medium",null);
sizeChoice.append("Large", null);
form.append(sizeChoice);
AnimChoice = new ChoiceGroup("Animation Choice", Choice.POPUP);
AnimChoice.append("Walk", null);
AnimChoice.append("Jump",null);
System.out.println(characterOne.getSize()+" WAN ting");
if(addChoice.equalsIgnoreCase("character1")) {
System.out.println("it is coming here character1");
if(characterOne.getSize()==0 ) {
sizeChoice.setSelectedIndex(0,true);
}else if(characterOne.getSize()==1) {
sizeChoice.setSelectedIndex(1,true);
}else if(characterOne.getSize()==2) {
sizeChoice.setSelectedIndex(2,true);
}
if(characterOne.getMovement()==0) {
AnimChoice.setSelectedIndex(0,true);
}else if(characterOne.getMovement()==1){
AnimChoice.setSelectedIndex(1,true);
}
}else if(addChoice.equalsIgnoreCase("character2")) {
System.out.println("it is coming here character2");
if(characterTwo.getSize()==0 ) {
sizeChoice.setSelectedIndex(0,true);
}else if(characterTwo.getSize()==1) {
sizeChoice.setSelectedIndex(1,true);
}else if(characterTwo.getSize()==2) {
sizeChoice.setSelectedIndex(2,true);
}
if(characterTwo.getMovement()==0) {
AnimChoice.setSelectedIndex(0,true);
}else if(characterTwo.getMovement()==1){
AnimChoice.setSelectedIndex(1,true);
}
}
form.append(AnimChoice);
form.addCommand(bkCmd);
form.addCommand(sltCmd);
form.setCommandListener(this);
form.append(new SimpleItem("Animation Preview"));
}
return form;
}
private void clearScreen(Graphics g) {
g.setColor(0xFFFFFF);
g.fillRect(0,0,getWidth(),getHeight());
}
class SimpleItem extends CustomItem {
public SimpleItem(String title) { super(title); }
// CustomItem abstract methods.
public int getMinContentWidth() { return 200; }
public int getMinContentHeight() { return 150; }
public int getPrefContentWidth(int width) {
return getMinContentWidth();
}
public int getPrefContentHeight(int height) {
return getMinContentHeight();
}
public void paint(Graphics g, int w, int h) {
g.setColor(0xFFFFFF);
g.fillRect(10,6,getWidth(),getHeight());
alice.setRefPixelPosition(10,6);
alice.nextFrame();
alice.paint(g);
repaint();
}
}
}
Hi, this is my class.