现在的位置: 首页 > 综合 > 正文

j2me学习笔记1

2014年01月18日 ⁄ 综合 ⁄ 共 861字 ⁄ 字号 评论关闭

Command使用

在form子类中用

    addCommand(new Command("Exit", Command.EXIT, 2));
    addCommand(new Command("Listen",Command.OK,1));
    addCommand(new Command("stop",Command.STOP,1));

添加command,第三个参数为优先级,影响到控件的位置。

事件添加

必须实现implements CommandListener 接口

并添加事件监听setCommandListener(CommandListener I);

  public void commandAction(Command command, Displayable displayable) {
    /** @todo Add command handling code */
    if (command.getCommandType() == Command.EXIT) {
// stop the MIDlet
      CMyMIDlet.quitApp();
    }
    else if(command.getCommandType()==Command.OK)
    {
      //display something~
      this.setTicker(new Ticker("running"));
    }
    else if(command.getCommandType()==Command.STOP){
      setTicker(null);
    }
  }
}

////

LCIUI包分为高级API和低级API

高级API包括:Screen的子类

低级API包括:Canvas的子类和Graphics类

Ticker类,一种图形显示,很搞笑,就是让一个东东在Form的标题上面一直滚动

示例代码如下:

{

  // if  a is Form instance

 a.setTicker(new Ticker("somestr"));

a.setTicker(null);//可以取消这个东东

}

抱歉!评论已关闭.