• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Useful Application do Command.ITEM

 
Isaias C. Barroso
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
Have anybody a useful application Example for the Command.ITEM on the Command Class?
Thanks
 
Debbie Argulkar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks.
 
sasinda Rukshan
Greenhorn
Posts: 4
Java Java ME Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" );
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic