Quick Start

List

 

 

1.Deal with menu command event

 

MIDlet:

 

public class TestMIDlet extends MIDlet{

         protected void startApp() throws MIDletStateChangeException {

                 ActionController controller = ActionController.getInstance(true);

                 controller.registerViewer(this);       //Register the MIDlet

 

                 MyKGameCanvas mgc = new MyKGameCanvas("MYGC");  //Create a GameCanvas

 

                 KCommand kc = new KCommand("TEST BUTTON", Command.HELP,1,"MYCMD",null);
                 mgc.addCommand(kc);
                 mgc.setCommandListener(controller);
                 Display.getDisplay(this).setCurrent(mgc);

         }

}

 

MyGameCanvas:

 

public class MyKGameCanvas extends KGameCanvas{

 

         public MyKGameCanvas(String uniqueID) {

                   super(uniqueID);

         }

         public void showString(String string){

                   Graphics g = this.getGraphics();

                   g.setColor(0xFFFFFFFF);

                   g.fillRect(0, 0, this.getWidth(), this.getHeight());

                   g.setColor(0xFF000000);

                   g.drawString(string, 0, 0, Graphics.TOP|Graphics.LEFT);

                   this.flushGraphics();

         }

}

 

Action:

 

public class TestAction implements Action{

         public void excute(KCommand cmd, Item item,  Displayable dis, ActionForward forward,Hashtable parameters) {

               

                   MyKGameCanvas mkc = ((MyKGameCanvas)dis);

                   mkc.showString("hello world! From "+mkc.getUniqueID()+"."+cmd.getUniqueID());

         }

}

 

Specify the Action in config file:

 

DEBUG=true        //open the debug model of KBOX

CMD.MYCMD.ACTION=action.TestAction

 

 

2.Deal with key pressed event

 

Key pressed Action:

 

public class TestKeyAction implements Action{

         public void excute(KCommand cmd, Item item,  Displayable dis, ActionForward forward,Hashtable parameters) {

                   MyKGameCanvas mkc = ((MyKGameCanvas)dis);

                  

                   Do your business here.

                   ..

         }

}

 

Specify the action of event

 

 

DEBUG=true        //open the debug model of KBOX

CMD.MYCMD.ACTION=action.TestAction

KEY.MYGC.FIRE.ACTION=action.TestKeyAction…

 

3.Parameter passing from  command

...

KCommand kc = new KCommand("TEST BUTTON", Command.HELP,1,"MYCMD").setAttribute("parameter","Hello world!");

...

 

4.Parameter passing from  configuration file :

Configuration file:

...

CMD.MYCMD.ACTION=action.TestAction

CMD.MYCMD.PARAMETERS.1=HELLO

CMD.MYCMD.PARAMETERS.2=WORLD

...

 

Action:

 ...

public void excute(KCommand cmd, Item item,  Displayable dis, ActionForward forward,Hashtable parameters) {

...

System.out.println(parameters.get("1"));//HELLO

System.out.println(parameters.get("2"));//HELLO

...

}

...

note: the parameter name in configuration file must be 1,2,3....

 

5.Application internationalization:

MsgResource msgRes = MsgResource.getInstance();

msgRes.loadRes(); //Call  when it's the first time to use MsgResource

Form form = new Form(msgRes.getMsg("title"));

 

Edit res.propery:

title=HELLO TITLE!

 

You can find the complete example in the “example” package.


Copyright © 2008 YiBin.h.
Licensed under the Apache License, Version 2.0.