Why do buttons have listener actions, but no command in LWUIT?

Is there a reason why in LWUIT a button may have its own ActionListener (via button.addActionListener) while the command is not working?

The only way to have a listener for a specific command is to add an ActionListener to the form and check the listener for which the Command event has occurred, as shown below?

    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();
}
+5
source share
1 answer

Well, I can’t say for sure why the people who wrote LWUIT made this decision, but there are several reasons why this makes sense.

, . , , , . , , , , Button .

, , API LWUIT LCDUI MIDP.

, :

2 ( ActionListener). ActionListener, , , 3 . , , , , , , , .

+6

All Articles