This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java Micro Edition and the fly likes Useful Application do Command.ITEM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Useful Application do Command.ITEM" Watch "Useful Application do Command.ITEM" New topic

Useful Application do Command.ITEM

Isaias C. Barroso
Ranch Hand

Joined: Jan 22, 2002
Posts: 165
Hello all,
Have anybody a useful application Example for the Command.ITEM on the Command Class?

Debbie Argulkar
Ranch Hand

Joined: Jul 26, 2002
Posts: 43
You use Command.ITEM to provide context sensitive Menu options. For example if you select a stock,
you can use the Command.ITEM to specify the Buy and Sell options.

See also:
Isaias C. Barroso
Ranch Hand

Joined: Jan 22, 2002
Posts: 165
sasinda Rukshan

Joined: Apr 01, 2011
Posts: 4

A quick test programme.

*When you add an Item Command as the default command for an item the command is executed automatically when you selct the item
*No meaning of adding a command of type ITEM to the form.It does not get context sensitive.(any way, how can it be )

package cmds;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

* @author sasinda
public class MidletCMD extends MIDlet implements CommandListener,ItemCommandListener,ItemStateListener {
public void startApp() {
Display dis=Display.getDisplay(this);

StringItem i1=new StringItem("lab i1", "sasinda",Item.BUTTON);
StringItem i2=new StringItem("lab i2", "sasinda",Item.PLAIN);
StringItem i3=new StringItem("lab i3", "sasinda",Item.HYPERLINK);
Item[] itms={i1,i2,i3};
Form frm=new Form("cmds", itms);

final Command frmCmd=new Command("frmCmd", "Item Command in the form", Command.ITEM, 2);
final Command i1Cmda=new Command("itmcmd i1 A", "Item Command a added to i1", Command.ITEM, 1);
final Command i1Cmdb=new Command("itmcmd i1 B", "Item Command b added to i1", Command.ITEM, 1);
final Command i1Cmdc=new Command("itmcmd i1 C", "Item Command c added to i1", Command.ITEM, 1);
final Command i1Cmdd=new Command("itmcmd i1 D", "Item Command D added as Default Itm Cmd to i1", Command.ITEM, 1);
final Command i2Cmdd=new Command("itmcmd i2 D", "Item Command D added as Default Itm Cmd to i2", Command.ITEM, 1);
final Command i3Cmda=new Command("itmcmd i3 a", "Item Command a added to i3", Command.ITEM, 1);

frm.addCommand(frmCmd);//this is not an context sensitive command.As it is added to the form.
//we can see that when the commands are added to the items they are context sensitive.



//set cmd listeners


//view form

public void pauseApp() {

public void destroyApp(boolean unconditional) {

public void commandAction(Command c, Displayable d) {
System.out.println("executed the "+c.getLongLabel()+" in "+d.getTitle() );

public void commandAction(Command c, Item item) {
System.out.println("executed the "+c.getLongLabel()+" in "+item.getLabel() );

public void itemStateChanged(Item item) {
System.out.println(" State of "+item.getLabel()+" changed" );

I agree. Here's the link:
subject: Useful Application do Command.ITEM
Similar Threads
What is a practical example of a nested static class
Example of use
File Watcher utility scheduling
Applet still useful ?
Using response.setContentLength in a Web Application ?