小编Boo*_*oon的帖子

为什么按钮在LWUIT中没有动作侦听器和命令?

是否有任何理由为什么在LWUIT中Button可以拥有自己的ActionListener(通过button.addActionListener)而Command不具备?

获取特定命令的唯一方法是将ActionListener添加到表单并检查侦听器,该事件来自哪个Command,如下所示?

    public void startApp() {
    Display.init(this);
    f = new Form("Mixed Record");
    exit = new Command("Exit");
    start = new Command("Start");
    Button button = new Button("Button");

    f.addCommand(exit);
    f.addCommand(start);
    f.addCommand(delete);
    f.addComponent(button);

    f.addCommandListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            if (ae.getCommand().equals(exit)) {
                //Do Exit command code
            } else if (ae.getCommand().equals(start)) {
                //Do Start command code
            }
        }
    });

    button.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            //Do button code
        }
    });

    f.show();
}
Run Code Online (Sandbox Code Playgroud)

java mobile lwuit actionlistener java-me

5
推荐指数
1
解决办法
1083
查看次数

标签 统计

actionlistener ×1

java ×1

java-me ×1

lwuit ×1

mobile ×1