×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Question Question regarding the container in LWUIT

    Hi experts. Please look at the following piece of code.

    PHP Code:
    import com.sun.lwuit.Form;

    //include other imports also here...

    public class Demo implements ActionListener{

    Form form ;
    List list;
    Label lbl_Day;
    ComboBox cmbox_dayList;
    public 
    Demo(){
        
    form = new Form("Demo");
       
    form.show();
       list = new List();
    }

    //Method to create components to form.
    private void addToScreen(){
      
    createLabel(lbl_Day,"Day",list);
      
    createComboBox(cmbox_dayList,new String[]{"Select","Monday","Tuesday"},list);
      
    TableLayout t1 = new TableLayout(52);
       
    TableLayout.setDefaultColumnWidth(50);
       
    Container c = new Container(t1);
       for (
    int i 0< list.size(); i++) {
            
    Object obj = list.getModel().getItemAt(i);
            
    c.addComponent((Componentobj);
        }
    form.addComponent(c);
    }
    private 
    void createLabel(Label lString text, List list) {
            
    = new Label(text);
            list.
    addItem(l);
        }

    public 
    void actionPerformed(ActionEvent ae){
    if(
    ae.getSource.equals(cmbox_listDay)){
          
    System.out.println("Some value is selected..");
    }

    }
    }

    private 
    void createComboBox(ComboBox cmboxObject[] items, List list) {
            
    cmbox = new ComboBox(items);
           
    cmbox.addActionListener(this);
            list.
    addItem(cmbox);
     }



    In the above code . one label and corresponding combox is created. But i am not able to add action listener to this comboBox through this logic.
    Also when i am using textfield and wants to get the text from the textfield. It is also not possible through this logic..


    I am using this logic to get the value selected from the combobox
    PHP Code:
    int index = list.size() - 1;
            
    ComboBox cmp = (ComboBoxform.getComponentAt(index);
            
    component = (ComboBox) list.getModel().getItemAt(index);
    if (
    component instanceof com.sun.lwuit.ComboBox) {
                
    MyDialog.showCustomDLG("Message""Yes"Dialog.TYPE_INFO);
                
    component.addActionListener(new ActionListener() {

                    public 
    void actionPerformed(ActionEvent ae) {
                        
    int index component.getSelectedIndex();
                        switch (
    index) {
                            case 
    0:
                                
    MyDialog.showCustomDLG("Message""Hello"Dialog.TYPE_INFO);
                                break;
                            case 
    1:
                                break;
                        }
                    }
                });


    Please give some idea how to get the selected value from combobox from this logic..
    Regards
    Rajan Verma

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Question regarding the container in LWUIT

    There are lots of LWUIT books and toutorials available around, better you download and read the same. As here the experts are not in the GUI technologies.

    Are you sure that the below quoted method was called?

    PHP Code:
    public void actionPerformed(ActionEvent ae) {
                        
    int index component.getSelectedIndex();
                        switch (
    index) {
                            case 
    0:
                                
    MyDialog.showCustomDLG("Message""Hello"Dialog.TYPE_INFO);
                                break;
                            case 
    1:
                                break;
                        }
                    } 
    If yes then what value it has returned?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Question regarding the container in LWUIT

    Yes , addaction listener method was called.

    One more thing i want to tell you is that .
    If i am using ComboBox cm = new ComboBox(new String[]{"Select","One","Two"});
    cm.addActionListener(cm); // This code is working fine..

    But in my project there are around a total of 200 fields including labels, Comboboxes,Textfield,etc.
    Using the above logic, this would be so much hard to use. That's why i want to create the components logically as described in entry 1 of this Thread. But i am able to addaction listener to them...

    Please Reply
    Regards
    Rajan Verma

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Question regarding the container in LWUIT

    Quote Originally Posted by rajan701v View Post
    But in my project there are around a total of 200 fields including labels, Comboboxes,Textfield,etc.
    Using the above logic, this would be so much hard to use. That's why i want to create the components logically as described in entry 1 of this Thread. But i am able to addaction listener to them...

    Please Reply
    You must not be using all the 200 component in the one container and hence there should not be any issues in that.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Question regarding the container in LWUIT

    I know i am using different container to add the components..

    Actually there are two cases:

    I created a global reference of ComboBox cmbox.
    Like ComboBox cmbox = null;//Globally declared...

    1.) Used a reference to create the object of the cmbox in the method createComboBox() as discussed previously.
    2.) Used a reference to create the object of the cmbox .
    cmbox = new ComboBox(new String[]{"Select"});


    Now in 2.) case when using addActionListener(); it is working fine.
    But not in 1.) case ... Is this the issue of getting the object of the ComboBox defined. And then only i can addActionListener().
    I think it can be the issue.

    Please Reply..
    Regards
    Rajan Verma

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Question regarding the container in LWUIT

    Yeah, this or anything else can be the issue, keep on trying the debugging and possible solutions, you will get it fix. Keep on trying.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  7. #7
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Question regarding the container in LWUIT

    but how can i get the instance of that particular cmbox.

    please reply.
    Regards
    Rajan Verma

  8. #8
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Question Re: Question regarding the container in LWUIT

    When using cmbox.addActionListener(this);

    I am getting NullPointerException...

    Please Reply..
    Regards
    Rajan Verma

  9. #9
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Question regarding the container in LWUIT

    Quote Originally Posted by rajan701v View Post
    When using cmbox.addActionListener(this);

    I am getting NullPointerException...

    Please Reply..
    check if cmbox is not null, and also you are implementing the ActionListener .
    is this of any help?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Question regarding the keypad of mobile
    By rajan701v in forum Mobile Java General
    Replies: 2
    Last Post: 2011-02-03, 06:42
  2. Need suggestions regarding the usage of LWUIT and J2ME Polish
    By kpvrlakshmi in forum Mobile Java Tools & SDKs
    Replies: 4
    Last Post: 2010-05-14, 23:47
  3. Lwuit Container paint
    By ingsaurabh in forum Mobile Java General
    Replies: 2
    Last Post: 2010-04-30, 05:56
  4. Regarding LWUIT
    By success_anil in forum Mobile Java General
    Replies: 1
    Last Post: 2009-08-14, 14:53
  5. Question regarding the bluetooth discovery
    By antonio5982 in forum Mobile Java Networking & Messaging & Security
    Replies: 7
    Last Post: 2007-10-26, 11:10

Posting Permissions

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