Meaningless Drivel is fun!*
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
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Useful Application do Command.ITEM" Watch "Useful Application do Command.ITEM" New topic
Author

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?
Thanks


Isaias
Debbie Argulkar
Ranch Hand

Joined: Jul 26, 2002
Posts: 43
HI,
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:
http://wirelesssoftware.info/midp_2.0/javax/microedition/lcdui/Command.html
Isaias C. Barroso
Ranch Hand

Joined: Jan 22, 2002
Posts: 165
Hi,
Thanks.
sasinda Rukshan
Greenhorn

Joined: Apr 01, 2011
Posts: 4

A quick test programme.

Note:
*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.

i1.addCommand(i1Cmda);
i1.addCommand(i1Cmdb);
i1.addCommand(i1Cmdc);
i1.setDefaultCommand(i1Cmdd);

i2.setDefaultCommand(i2Cmdd);
i3.addCommand(i3Cmda);

//set cmd listeners

frm.setCommandListener(this);//
i1.setItemCommandListener(this);
i2.setItemCommandListener(this);
i3.setItemCommandListener(this);


//view form
dis.setCurrent(frm);
}

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" );
}
}


SCJP, OCWCD, OCMAD, OCBCD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Useful Application do Command.ITEM