Command type


J2ME MIDlet applications do not have 'push-buttons' like, for example, Windows applications. Instead, the user may use so called 'commands' for implementing the push button functionality.

Commands can be added to form or to canvas. When a form is displayed on the device screen (by calling the 'showForm' procedure), the commands added will be inserted on to the form. If a display is then switched to canvas ('showCanvas'), the commands associated with the form will be removed from the screen and commands associated with the canvas will be displayed on the screen. Take a look at the following example:

  var formCommand, canvasCommand: command;
  begin
    formCommand := createCommand('Show canvas', CM_SCREEN, 1);
    canvasCommand := createCommand('Show form', CM_SCREEN, 1);
    
    { add the canvas form onto the canvas (the canvas is displayed by default) }
    addCommand(canvasCommand);

    { switch to form display }
    showForm;

    { add the form command to the form display }
    addCommand(formCommand);

    { forever switch between the canvas and the form display }
    while true do
    begin
      if getClickedCommand = formCommand then
        showCanvas;
      if getClickedCommand = canvasCommand then
        showForm;
    end;
  end.

Since the mobile devices do not have large displays, not all of the commands can be displayed on the screen. It is up to the device to decide which (if any) commands will be displayed on the display. Other commands (preferably those with the less priority) can be grouped inside some sort of the 'pop-up' menu which can be accessed by pressing a special 'options' key on the device keypad.

Some devices (such as Motorola mobile phones) will not display the command immediately after 'addCommand' is called; they will wait for a call to 'repaint' precedure.