javauis/tsrc/fute/lcdui/Midp_StringItem_01/src/StringItemTests2.java
changeset 87 1627c337e51e
parent 26 dc7c549001d5
equal deleted inserted replaced
80:d6dafc5d983f 87:1627c337e51e
    61     private Command cmdClear = new Command("Clear form", Command.SCREEN, 1);
    61     private Command cmdClear = new Command("Clear form", Command.SCREEN, 1);
    62 
    62 
    63     // Commands for the StringItems
    63     // Commands for the StringItems
    64     private Command cmdItem1 = new Command("Itemcommand1", Command.ITEM, 1);
    64     private Command cmdItem1 = new Command("Itemcommand1", Command.ITEM, 1);
    65     private Command cmdItem2 = new Command("Itemcommand2", Command.ITEM, 1);
    65     private Command cmdItem2 = new Command("Itemcommand2", Command.ITEM, 1);
       
    66     // Command to exit the MIDlet
       
    67     private Command cmdExit = new Command("Exit", Command.EXIT, 1);
    66 
    68 
    67     /**
    69     /**
    68      * Signals the MIDlet to start and enter the Active state.
    70      * Signals the MIDlet to start and enter the Active state.
    69      */
    71      */
    70     protected void startApp()
    72     protected void startApp()
    79         mainForm.append(cgLabel);
    81         mainForm.append(cgLabel);
    80         mainForm.append(cgText);
    82         mainForm.append(cgText);
    81 
    83 
    82         mainForm.addCommand(cmdAdd);
    84         mainForm.addCommand(cmdAdd);
    83         mainForm.addCommand(cmdForward);
    85         mainForm.addCommand(cmdForward);
       
    86         mainForm.addCommand(cmdExit);
    84         mainForm.setCommandListener(this);
    87         mainForm.setCommandListener(this);
    85         stringItemForm.addCommand(cmdBack);
    88         stringItemForm.addCommand(cmdBack);
    86         stringItemForm.addCommand(cmdClear);
    89         stringItemForm.addCommand(cmdClear);
    87         stringItemForm.setCommandListener(this);
    90         stringItemForm.setCommandListener(this);
    88         Display.getDisplay(this).setCurrent(mainForm);
    91         Display.getDisplay(this).setCurrent(mainForm);
   110      *@param  c  This is the command responsible for the event.
   113      *@param  c  This is the command responsible for the event.
   111      *@param  s  Should be equal to this.
   114      *@param  s  Should be equal to this.
   112      */
   115      */
   113     public void commandAction(Command c, Displayable s)
   116     public void commandAction(Command c, Displayable s)
   114     {
   117     {
   115         if (c == cmdAdd)
   118         if(c == cmdAdd)
   116         {
   119         {
   117             // Create correct type of stringitem
   120             // Create correct type of stringitem
   118             int index = cgType.getSelectedIndex();
   121             int index = cgType.getSelectedIndex();
   119             if (index == 0)
   122             if(index == 0)
   120                 si = new StringItem("", "", Item.PLAIN);
   123                 si = new StringItem("", "", Item.PLAIN);
   121             else
   124             else
   122             {
   125             {
   123                 if (index == 1)
   126                 if(index == 1)
   124                     si = new StringItem("", "", Item.HYPERLINK);
   127                     si = new StringItem("", "", Item.HYPERLINK);
   125                 else if (index == 2)
   128                 else if(index == 2)
   126                     si = new StringItem("", "", Item.BUTTON);
   129                     si = new StringItem("", "", Item.BUTTON);
   127                 si.addCommand(cmdItem1);
   130                 si.addCommand(cmdItem1);
   128                 si.addCommand(cmdItem2);
   131                 si.addCommand(cmdItem2);
   129                 si.setItemCommandListener(this);
   132                 si.setItemCommandListener(this);
   130             }
   133             }
   131 
   134 
   132             // Set the label
   135             // Set the label
   133             index = cgLabel.getSelectedIndex();
   136             index = cgLabel.getSelectedIndex();
   134             if (index == 0)
   137             if(index == 0)
   135                 si.setLabel("");
   138                 si.setLabel("");
   136             else
   139             else
   137                 si.setLabel(cgLabel.getString(index));
   140                 si.setLabel(cgLabel.getString(index));
   138             // Set the text
   141             // Set the text
   139             index = cgText.getSelectedIndex();
   142             index = cgText.getSelectedIndex();
   140             si.setText(cgText.getString(index));
   143             si.setText(cgText.getString(index));
   141             stringItemForm.append(si);
   144             stringItemForm.append(si);
   142             Display.getDisplay(this).setCurrent(stringItemForm);
   145             Display.getDisplay(this).setCurrent(stringItemForm);
   143         }
   146         }
   144 
   147 
   145         else if (c == cmdBack)
   148         else if(c == cmdBack)
   146         {
   149         {
   147             Display.getDisplay(this).setCurrent(mainForm);
   150             Display.getDisplay(this).setCurrent(mainForm);
   148         }
   151         }
   149         else if (c == cmdClear)
   152         else if(c == cmdClear)
   150         {
   153         {
   151             stringItemForm.deleteAll();
   154             stringItemForm.deleteAll();
   152         }
   155         }
   153         else if (c == cmdForward)
   156         else if(c == cmdForward)
   154         {
   157         {
   155             Display.getDisplay(this).setCurrent(stringItemForm);
   158             Display.getDisplay(this).setCurrent(stringItemForm);
       
   159         }
       
   160         else if(c == cmdExit)
       
   161         {
       
   162             this.notifyDestroyed();
   156         }
   163         }
   157     }
   164     }
   158 
   165 
   159     public void commandAction(Command c, Item i)
   166     public void commandAction(Command c, Item i)
   160     {
   167     {