×

Discussion Board

Results 1 to 4 of 4

Thread: Add Commands

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    35

    Thumbs up Add Commands

    Hi,
    I want to add more than two commands in my Lwuit Form not getting correct way .
    addCommand(exit);
    addCommand(count);
    addCommand(info);

    pls do help with code.

  2. #2
    Super Contributor
    Join Date
    May 2008
    Location
    Helsinki, Finland
    Posts
    1,098

    Re: Add Commands

    Hello there, neerajj50

    Please could you describe a bit more, how the commands are not coming on your Form correctly, how are you implementing them...can you share that part of the code maybe?

    To start with, basically it is quite easy to use the LWUIT commands if you have been doing MIDlet development before. However, some things in LWUIT that you should note though.

    I found for you a very good tutorial on LWUIT, I am sure it would help you in your development efforts.

    This is the part that handles Commands:

    Using Commands

    LWUIT includes the concept of a command. A command is something that your user can do in your application. LWUIT decides how to show the command on the screen and how the user makes it happen. Usually, commands are assigned to the soft buttons on a mobile phone. LWUIT will normally show commands as labels at the bottom corners of the screen; the user can invoke them by pressing the corresponding soft button. On touch devices, the user can touch directly on a command to invoke it.
    Conceptually, commands in LWUIT closely resemble commands in MIDP. Some of the details are slightly different, but if you already understand MIDP commands, you'll have no trouble with LWUIT commands.
    In LWUIT, create commands and add them to forms. Then register a listener object with the form to be notified when the user invokes a command.
    This simple example creates a form and registers a listener. The listener shuts down the application when it is invoked.
    import javax.microedition.midlet.*;

    import com.sun.lwuit.*;
    import com.sun.lwuit.events.*;

    public class HelloLWUITMidlet extends MIDlet implements ActionListener {

    private Form mForm;

    public void startApp() {
    if (mForm == null) {
    Display.init(this);

    Form f = new Form("Hello, LWUIT!");

    Command exitCommand = new Command("Exit");
    f.addCommand(exitCommand);
    f.setCommandListener(this);

    f.show();
    }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void actionPerformed(ActionEvent ae) {
    destroyApp(true);
    notifyDestroyed();
    }
    }
    If you add more than two commands to a form, they won't fit on the two available soft buttons. In this case, one of the soft buttons will become a menu. When the user invokes the menu, it shows a list of the rest of the commands.
    When your listener's actionPerformed() method must respond to more than one command, you can find out which one was invoked by calling the ActionEvent's getCommand() method.

    The full tutorial and more on LWUIT is here: https://lwuit.dev.java.net/

    Please could you first try implementing the example code for your commands, and let us know how it goes?

    Hope this helps!

    Best Regards,
    Marko
    [FONT="Comic Sans MS"][COLOR="Blue"][/COLOR][I]Marko Lumivuori
    Technical Support
    +358 40 8019330
    [email]marko.lumivuori@nokia.com[/email][/I][/FONT]

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    35

    Thumbs up Re: Add Commands

    This is the code :
    package vmsbpackage;

    import com.sun.lwuit.Button;
    import com.sun.lwuit.Command;
    import com.sun.lwuit.Component;
    import com.sun.lwuit.Container;
    import com.sun.lwuit.Dialog;
    import com.sun.lwuit.Form;
    import com.sun.lwuit.Image;
    import com.sun.lwuit.Label;
    import com.sun.lwuit.events.ActionEvent;
    import com.sun.lwuit.events.ActionListener;
    import com.sun.lwuit.layouts.BoxLayout;
    import com.sun.lwuit.layouts.GridLayout;
    import com.sun.lwuit.list.DefaultListCellRenderer;
    import java.io.IOException;
    import java.util.Vector;
    import javax.microedition.rms.RecordEnumeration;
    import javax.microedition.rms.RecordStore;
    import javax.microedition.rms.RecordStoreException;
    import javax.microedition.rms.RecordStoreNotOpenException;

    public class MenuItems extends Form {

    Button btn_admin,btn_transaction,btn_mines,btn_sodddo,btn_vagus_complex;
    Form form;
    private Image image;
    Command info;
    Command exit;
    Command count;

    Container c;

    Label lbl_hhrid,lbl_space;;
    Container container;
    boolean exit_flag=true;
    public MenuItems(String title) {

    super(title);
    initialisaton();
    addComponent();
    }

    public Label newLabel()
    {
    Label spaceLabel = new Label(" ");
    spaceLabel.setAlignment(Component.CENTER);
    spaceLabel.getUnselectedStyle().setBgTransparency(0);
    return spaceLabel;
    }
    public void initialisaton()
    {
    setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    this.setMenuCellRenderer(new DefaultListCellRenderer(true));

    container=new Container(new GridLayout(2, 2));
    //setLayout(new GridLayout(1, 1));
    lbl_space=new Label(" ");
    lbl_hhrid=new Label(" HHR ID :"+ApplicationMidlet.hhr_id);
    lbl_hhrid.getUnselectedStyle().setFgColor(13047173);
    try
    {
    btn_admin = new Button(Image.createImage("/admin.png"));
    btn_mines= new Button(Image.createImage("/operations.png"));
    btn_vagus_complex=new Button(Image.createImage("/operations.png"));
    }
    catch (IOException ex)
    {
    ex.printStackTrace();
    }
    //btn_admin.setTextPosition(Component.RIGHT);

    //btn_mines.setTextPosition(Component.RIGHT);
    btn_vagus_complex.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent arg0)
    {
    ApplicationMidlet.vagusComplexForm.show();
    }
    });
    btn_mines.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0)
    {

    if(ApplicationMidlet.midlet.access_to_sigao)
    {
    ApplicationMidlet.loadParameterOREForm.getLongRouteCodes();
    ApplicationMidlet.loadParameterOREForm.getProductCodes();
    ApplicationMidlet.loadParameterOREForm.getSourceLocation();
    ApplicationMidlet.loadParameterOREForm.getSourceSubLocation();
    ApplicationMidlet.loadParameterOREForm.getDestinationLocation();
    ApplicationMidlet.loadParameterOREForm.getBillingCategory();
    ApplicationMidlet.loadParameterOREForm.getMachineCodes();

    ApplicationMidlet.loadParameterREJForm.getShortRouteCodes();
    ApplicationMidlet.loadParameterREJForm.getProductCodes();
    ApplicationMidlet.loadParameterREJForm.getSourceLocation();
    ApplicationMidlet.loadParameterREJForm.getSourceSubLocation();
    ApplicationMidlet.loadParameterREJForm.getDestinationLocation();
    ApplicationMidlet.loadParameterREJForm.getBillingCategory();
    ApplicationMidlet.loadParameterREJForm.getMachineCodes();

    ApplicationMidlet.uf.getDestinationLocation();
    ApplicationMidlet.uf.getDestinationSublocation();

    }

    //ApplicationMidlet.forcefullyClosedForm.getDestinationLocation();
    // ApplicationMidlet.forcefullyClosedForm.getDestinationSublocation();

    ApplicationMidlet.TransactionsForm.show();
    }
    });

    btn_sodddo= new Button("Soddo",image);
    btn_sodddo.setTextPosition(Component.RIGHT);
    // btn_vagus_complex= new Button("Vagus Complex",image);
    // btn_vagus_complex.setTextPosition(Component.RIGHT);
    btn_admin.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent arg0) {

    ApplicationMidlet.admin.show();
    //String s=ApplicationMidlet.midlet.getCheckSum("abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789cfgvbh1254kl");
    // for(int i=0;i<256;i++)
    // {
    // int s=i;
    // Dialog.show("INFO","char is : "+(char)s+"\n"+"ASCII : "+s,"Ok","Cancel");
    // Dialog.show("INFO", ApplicationMidlet.midlet.displayHexString(""+(char)s),"Ok", "Cancel");
    // }
    }
    });
    exit = new Command("Exit")
    {

    public void actionPerformed(ActionEvent ev)
    {
    RecordStore rs =null;
    try
    {
    rs = RecordStore.openRecordStore("VMSBOfflineRecordMemory", false);
    int records = rs.getNumRecords();
    rs.closeRecordStore();
    exit_flag=Dialog.show("INFO", "Number of transactions : " + records, "Ok", "Cancel");
    exitApp(exit_flag);
    }
    catch (RecordStoreException ex)
    {
    exit_flag=Dialog.show("INFO", "No records present !", "Ok", "Cancel");
    exitApp(exit_flag);
    }
    finally
    {
    try
    {
    rs.closeRecordStore();
    }
    catch (RecordStoreNotOpenException ex)
    {
    ex.printStackTrace();
    }
    catch (RecordStoreException ex)
    {
    ex.printStackTrace();
    }
    }

    }
    };
    info = new Command ("Info")
    {

    public void actionPerformed (ActionEvent ev)
    {System.out.println("Inside Info Button");
    Dialog.show ("INFO", "VMSB", "OK", "Cancel");
    //ApplicationMidlet.midlet.errorTone();
    }
    };

    // btn_transaction.addActionListener(new ActionListener() {
    //
    // public void actionPerformed(ActionEvent arg0) {
    // // TODO Auto-generated method stub
    //
    // form = new Transactions("i-TEK 4rMines");
    //
    // setTransitionOutAnimator(ApplicationMidlet.out);
    // form.setTransitionOutAnimator(ApplicationMidlet.in);
    //
    // form.show();

    //
    // }
    //
    // });
    count=new Command("Get Count")
    {
    public void actionPerformed(ActionEvent ae)
    {System.out.println("Inside DisplayCountButton");
    displayCount();
    }
    };

    //


    }

    public void addComponent()
    {
    addComponent(lbl_hhrid);
    addComponent(lbl_space);
    container.addComponent(btn_admin);
    container.addComponent(btn_mines);
    container.addComponent(btn_vagus_complex);
    addComponent(container);
    // addComponent(btn_admin);
    // addComponent(btn_mines);
    addCommand(exit);
    addCommand(count,1);
    addCommand(info,1);


    }
    private void exitApp(boolean end_flag)
    {
    if (end_flag)
    {
    ApplicationMidlet.midlet.destroyApp(true);
    ApplicationMidlet.midlet.notifyDestroyed();
    }

    }
    private void displayCount()
    {
    String info="";
    try
    {System.out.println("Inside DisplayCount");
    ApplicationMidlet.midlet.routineDate();
    String rs_name = ApplicationMidlet.midlet.myDate.substring(0, 8);
    RecordStore rs_ = RecordStore.openRecordStore(rs_name, false);
    RecordEnumeration re = rs_.enumerateRecords(null, null, false);
    if (re.numRecords() > 0)
    {
    while (re.hasNextElement())
    {
    byte[] bt = re.nextRecord();
    String name = new String(bt);


    }
    catch (Exception e)
    {
    Dialog.show("INFO", "No records !", "Ok", "Cancel");
    }
    }


    }

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    35

    Re: Add Commands

    Using LWUIT framework to develop mobile application. In LWUIT by default first command is placed in the left and subsequent commands will be placed in the right menu of the form including the command which is already placed in form left.I need to add two menus to form.Left menu contains general application specific commands such as "Minimize","Back" and "Exit". Right Menu contains screen specific commands such as "Play Audio","Play Video" etc... Initially left softbutton of the form contains the text "Options" and the right softbutton of the form contains the text "Menu". When user selects "Options", a menu will be displayed with the following commands: Minimize Back Exit When user selects right soft button "Menu", a menu will be displayed with screen specific commands: Play Audio Play Video etc... Commands of the right menu keeps changing from one form to another form, whereas the commands of left menu remains the same for all screens(forms). I know command menu can be customized by overriding "Form.createCommandList(Vector)" which returns a list. But here in my case I need two lists(menus). One at the left of the form and the other one at the right of the form.Please do help me in resolving this issue.

Similar Threads

  1. Add commands in canvas.
    By yama.raol in forum Mobile Java General
    Replies: 2
    Last Post: 2010-04-23, 10:09
  2. Add commands to j2mepolish TreeItem
    By tharindufit in forum Mobile Java General
    Replies: 1
    Last Post: 2008-09-30, 12:46
  3. Can we add commands in appuifw.selection_list?
    By shail229 in forum Symbian
    Replies: 2
    Last Post: 2008-06-27, 08:13
  4. Add Commands to Canvas
    By LiveRock in forum Mobile Java General
    Replies: 1
    Last Post: 2003-10-30, 13:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×