所有的可视组件都位于需要经由MIDlet来显示,而MIDlet上的所有事件,包括键盘事件,按钮事件提交到ActionController 上, ActionController跟据配置文件,将事件转发给相应的Action,Action将处理结果得到的可视组件(Displayable)通过 ActionForward返回MIDlet显示。
KBOX的使用非常简单, 以一个HELLO WORLD 为例:
创建一个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); } … } |
创建一个Canvas:
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(); } } |
[1] [2] 下一页