procedure addCommand(cmd: command);  

    .   (    Motorola)      ,      repaint.  ,   'addCommand'    repaint. 





function choiceAppendString(choiceID: integer; itemText:string):integer;  

       choiceID.      . 

  var 
    choiceGroupID: integer; 
    NY, LA: integer; 
  begin 
    showForm; 
    choiceGroupID := formAddChoice('Where do you live?', CF_EXCLUSIVE); 
    NY := choiceAppendString(choiceGroupID, 'New York'); 
    LA := choiceAppendString(choiceGroupID, 'Los Angeles'); 
  end. 





function choiceAppendStringImage(choiceID: integer; itemText:string; img:image):integer;  

         choiceID.       

  var 
    choiceGroupID: integer; 
    NY, LA: integer; 
  begin 
    showForm; 
    choiceGroupID := formAddChoice('Where do you live?', CF_EXCLUSIVE); 
    NY := choiceAppendStringImage(choiceGroupID, 'New York', loadImage('/NY.png')); 
    LA := choiceAppendStringImage(choiceGroupID, 'Los Angeles', loadImage('/LA.png')); 
  end. 
  
  



function choiceGetSelectedIndex(choiceID: integer):integer;  

      -1,      .    CH_MULTIPLE     -1,      choiceIsSelected. 





function choiceIsSeected(choiceID: integer; itemIndex:integer):boolean;  

 true    'choiceID'     'itemIndex'. 

  var 
    choiceGroupID: integer; 
    NY, LA: integer; 
  begin 
    showForm; 
    choiceGroupID := formAddChoice('Where do you live?', CF_EXCLUSIVE); 
    NY := choiceAppendStringImage(choiceGroupID, 'New York', loadImage('/NY.png')); 
    LA := choiceAppendStringImage(choiceGroupID, 'Los Angeles', loadImage('/LA.png')); 
    if choiceIsSelected(choiceGroupID, NY) then  
      formAddString('New York'); 
    else 
      formAddString('Los Angeles'); 
  end. 





procedure clearForm;  

      . 

  var 
    label_id, textField_id: integer; 
  begin 
    label_id := formAddString('Hello world'); 
    textField_id := formAddTextField('Enter your name', 'Mr.Smith', 20, TF_ANY); 
    showForm; 
    delay(2000); 
    clearForm; 
    delay(2000); 
  end. 





function createCommand(label:string; commandType:integer; priority:integer): command;  

       label.     .      'priority',     .  'commandType'     . ,   ,      CM_BACK,        "" (   -,  ),    ,     . 'commandType'    : 

  CM_SCREEN -     
  CM_BACK  
  CM_CANCEL  
  CM_OK  
  CM_HELP  
  CM_STOP  
  CM_EXIT  
  CM_ITEM  

  var 
    exitCmd, pauseCmd: command; 
  begin 
    exitCmd := createCommand('Exit', CM_EXIT, 1); 
    pauseCmd := createCommand('Pause', CM_SCREEN, 1); 
    addCommand(exitCmd); 
    addCommand(pauseCmd); 
  end. 





function emptyCommand:command;  

 ,      .         (    ),            -. 

  var 
    ok, clicked:command; 
  begin 
    ok := createCommand('OK', CM_OK, 1); 
    addCommand(ok); 
    repeat 
      clicked := getClickedCommand; 
    until clicked <> emptyCommand; 
    if clicked = ok then halt else doSomething... 
  end. 




function formAddChoice(label:string; choiceType:integer):integer;  

    .   ID  . 'choiceType'     : 

  CH_EXCLUSIVE -        
  CH_MULTIPLE -        
 




function formAddGauge(label:string; isInteractive:boolean; maxValue, initialValue:integer):integer;  

   ""  .   ID  .  'isInteractive'   'false',      "". 

  var gauge_id: integer; 
  begin 
    gauge_id := formAddGauge('Choose your age', true, 100, 18); 
    showForm; 
    delay(2000); 
  end.






function formAddImage(i:image):integer; 

   .   ID  . 

  var 
    image_id: integer; 
  begin 
    image_id := formAddImage(loadImage('/logo.png')); 
    showForm; 
    delay(2000); 
  end. 





function formAddSpace:integer;  

   .      .   ID  . 

  var 
    label_id, space_id, textField_id: integer; 
  begin 
    label_id := formAddString('Hello world'); 
    space_id := formAddSpace(); 
    textField_id := formAddTextField('Enter your name', 'Mr.Smith', 20, TF_ANY); 
    showForm; 
    delay(2000); 
  end. 





function formAddString(s:string):integer;  

   ()  .   ID  . 

  var 
    label_id: integer; 
  begin 
    label_id := formAddString('Hello world'); 
    showForm; 
    delay(2000); 
  end. 





function formAddTextField(prompt, defaultValue: string; maxSize: integer; constraints:integer):integer;  

    .   ID   .   'prompt'  ,    , 'defaultValue' - ,     , 'maxSize' -    ,    . 'constraints'     : 

  TF_ANY -       
  TF_EMAIL -           
  TF_NUMERIC -         
  TF_PHONENUMBER -          
  TF_URL -          (URL)  

  var 
    textField_id: integer; 
  begin 
    textField_id := formAddTextField('Enter your name', 'Mr.Smith', 20, TF_ANY); 
    showForm; 
    delay(2000); 
  end. 




function formGetText(textFieldID:integer):string;  

 ,      'textFieldID'.  'textFieldID'     ,       -    . 





function formGetValue(gaugeID:integer):integer;  

  ""   'gaugeID'.  ""    ,   -1. 

  var 
    gauge_id, value: integer; 
  begin 
    gauge_id := formAddGauge('Choose your age', true, 100, 18); 
    showForm; 
    value := formGetValue(gauge_id); 
    delay(2000); 
  end. 
  
  
  
  
  procedure formRemove(item:integer);  

   . 

  var 
    textField:integer; 
  begin 
    showForm; 
    textField := formAddTextField('Name', '', 20, TF_ANY); 
    delay(1000); 
    formRemove(textField); 
  end. 




procedure formSetText(textFieldID:integer; text:string);  

       'textFieldID'.




procedure formSetValue(gaugeID:integer; value:integer);  

  ""   'gaugeID'. 


  
  
  
function getClickedCommand: command;  

    . 

  var 
    exitCmd, clicked: command; 
  begin 
    exitCmd := createCommand('Exit', CM_EXIT, 1); 
    addCommand(exitCmd); 
    repeat 
      clicked := getClickedCommand; 
    until clicked <> emptyCommand; 
  end. 





function getTextBoxString:string;  

 ,     (TextBox). 

  var 
    cont : command; 
    quote : string; 
  begin 
    showTextBox('Enter your favorite quote', 'To be or not to be', 200, TF_ANY); 
    cont := createCommand('Continue', CM_SCREEN, 1); 
    addCommand(cont); 

    repeat 
      delay(100); 
    until getClickedCommand <> emptyCommand; 

    quote := getTextBoxString; 

    ...      
  end.





function menuAppendString(text: string): integer;  

    .       . 

  var 
    tetris, minesweeper, snake : integer; 
    play, clicked : command;    
  begin 
    showMenu('Select a game', CH_IMPLICIT); 
     
    tetris := menuAppendString('Tetris'); 
    minesweeper := menuAppendString('Minesweeper'); 
    snake := menuAppendString('Snake'); 

    play := createCommand('Play', CM_SCREEN, 1); 
    addCommand(play); 

    repeat 
      delay(100); 
      clicked := getClickedCommand; 
    until clicked = play; 

    showCanvas; //      . 

    if menuGetSelectedIndex = tetris then playTetris; 
    if menuGetSelectedIndex = minesweeper then playMinesweeper; 
    if menuGetSelectedIndex = snake then playSnake; 
    ... 
  end.







function menuAppendStringImage(text: string; img:image): integer;  

      .       . 

  var 
    tetris, minesweeper, snake : integer; 
    play, clicked : command;    
  begin 
    showMenu('Select a game', CH_IMPLICIT); 
     
    tetris := menuAppendStringImage('Tetris', loadImage('/tetris.png')); 
    minesweeper := menuAppendStringImage('Minesweeper', loadImage('/mine.png')); 
    snake := menuAppendStringImage('Snake', loadImage('/snake.png')); 

    play := createCommand('Play', CM_SCREEN, 1); 
    addCommand(play); 

    repeat 
      delay(100); 
      clicked := getClickedCommand; 
    until clicked = play; 

    showCanvas; //      . 

    if menuGetSelectedIndex = tetris then playTetris; 
    if menuGetSelectedIndex = minesweeper then playMinesweeper; 
    if menuGetSelectedIndex = snake then playSnake; 
    ... 
  end. 







function menuGetSelectedIndex: integer;  

    .      ,  -1. 

  var 
    tetris, minesweeper, snake : integer; 
    play, clicked : command;    
  begin 
    showMenu('Select a game', CH_IMPLICIT); 
     
    tetris := menuAppendStringImage('Tetris', loadImage('/tetris.png')); 
    minesweeper := menuAppendStringImage('Minesweeper', loadImage('/mine.png')); 
    snake := menuAppendStringImage('Snake', loadImage('/snake.png')); 

    play := createCommand('Play', CM_SCREEN, 1); 
    addCommand(play); 

    repeat 
      delay(100); 
      clicked := getClickedCommand; 
    until clicked = play; 

    showCanvas; //      . 

    if menuGetSelectedIndex = tetris then playTetris; 
    if menuGetSelectedIndex = minesweeper then playMinesweeper; 
    if menuGetSelectedIndex = snake then playSnake; 
    ... 
  end. 







function menuIsSelected(index: integer): boolean;  

 'true',      . 

  var 
    tetris, minesweeper, snake : integer; 
    play, clicked : command;    
  begin 
    showMenu('Select a game', CH_IMPLICIT); 
     
    tetris := menuAppendStringImage('Tetris', loadImage('/tetris.png')); 
    minesweeper := menuAppendStringImage('Minesweeper', loadImage('/mine.png')); 
    snake := menuAppendStringImage('Snake', loadImage('/snake.png')); 

    play := createCommand('Play', CM_SCREEN, 1); 
    addCommand(play); 

    repeat 
      delay(100); 
      clicked := getClickedCommand; 
    until clicked = play; 

    showCanvas; //      . 

    if menuIsSelected(tetris) then playTetris; 
    if menuIsSelected(minesweeper) then playMinesweeper; 
    if menuIsSelected(snake) then playSnake; 
    ... 
  end. 






procedure playAlertSound;  

 ,     (Alert). 

  var 
    cm : command; 
  begin 
    showAlert('Message', 'New message arrived', loadImage('/img1.png'), ALERT_INFO); 
    playAlertSound; 

    cm := createCommand('OK', CM_OK, 1); 
    addCommand(cm); 

    repeat 
      delay(100); 
    until getClickedCommand <> emptyCommand; 

    showForm; //    . 
    ...      
  end. 



procedure removeCommand(cmd: command);  

    . 





procedure setTicker(s:string);  

    " ". 

  begin 
    showForm; 
    setTicker('MIDlet created with MIDletPascal'); 
    delay(5000); 
  end. 






procedure showAlert(title: string; message:string; img:image; alertType:alert);  

    .         ( )     .        .     : 

  ALERT_INFO  
  ALERT_WARNING  
  ALERT_ERROR  
  ALERT_ALARM  
  ALERT_CONFIRMATION  

  var 
    cm : command; 
  begin 
    showAlert('New message', 'You have just received a message from MrSmith', loadImage('/img1.png'), 
      ALERT_INFO); 
    playAlertSound; 

    cm := createCommand('Read', CM_OK, 1); 
    addCommand(cm); 

    repeat 
      delay(100); 
    until getClickedCommand <> emptyCommand; 

    showForm; //     
    ...      
  end. 





procedure showCanvas;  

   (canvas)   .       .      (labels), ,       .  , ,     ;  ,     .        . 

  var 
    label_id, textField_id: integer; 
  begin 
    label_id := formAddString('Hello world'); 
    textField_id := formAddTextField('Enter your name', 'Mr.Smith', 20, TF_ANY); 
    showForm; 
    delay(2000); 
    showCanvas; 
    drawText('Hello world', 0, 0); 
    repaint; 
    delay(2000); 
  end. 





procedure showForm;  

    .       .      (labels), ,       .  , ,     ;  ,     .        . 

  var 
    label_id, textField_id: integer; 
  begin 
    label_id := formAddString('Hello world'); 
    textField_id := formAddTextField('Enter your name', 'Mr.Smith', 20, TF_ANY); 
    showForm; 
    delay(2000); 
  end. 





procedure showMenu(title:string; menuType:integer);  

    .    ( )        . 'menuType'    : 

  CH_IMPLICIT -       
  CH_EXCLUSIVE -  -       
  CH_MULTIPLE -       
 
   

  var 
    tetris, minesweeper, snake : integer; 
    play, clicked : command;    
  begin 
    showMenu('Select a game', CH_IMPLICIT); 
     
    tetris := menuAppendString('Tetris'); 
    minesweeper := menuAppendString('Minesweeper'); 
    snake := menuAppendString('Snake'); 

    play := createCommand('Play', CM_SCREEN, 1); 
    addCommand(play); 

    repeat 
      delay(100); 
      clicked := getClickedCommand; 
    until clicked = play; 

    showCanvas; //        . 

    if menuGetSelectedIndex = tetris then playTetris; 
    if menuGetSelectedIndex = minesweeper then playMinesweeper; 
    if menuGetSelectedIndex = snake then playSnake; 
    ... 
  end. 





procedure showTextBox(title: string; initialContents: string; maxSize: integer; constraints: integer);  

   (TextBox)  .            ( )       . 'constraints'    : 

  TF_ANY -       
  TF_EMAIL -           
  TF_NUMERIC -         
  TF_PHONENUMBER -          
  TF_URL -          (URL)  

  var 
    cont : command; 
    quote : string; 
  begin 
    showTextBox('Enter message, '', 200, TF_ANY); 
    cont := createCommand('Send', CM_SCREEN, 1); 
    addCommand(cont); 

    repeat 
      delay(100); 
    until getClickedCommand <> emptyCommand; 

    quote := getTextBoxString; 

    ...      
  end. 