×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    6

    LWUIT, S40(2.0) - From.getComponentCount() returns 1 always

    Hi,

    I have started to learn lwuit for S40 and I immediately encountered this problem. I am using lwuit.Form as container for components. Calling getComponentCount on the form instance always gives 1.

    Code:
    import com.sun.lwuit.*;
    import com.sun.lwuit.animations.CommonTransitions;
    import com.sun.lwuit.events.ActionEvent;
    import com.sun.lwuit.events.ActionListener;
    import com.sun.lwuit.layouts.BoxLayout;
    import com.sun.lwuit.util.Resources;
    import java.io.IOException;
    import javax.microedition.midlet.MIDlet;
    
    /**
     * @author rth
     */
    public class Midlet extends MIDlet implements ActionListener {
    
        private Command exitCmd;
        private Form form1;
        private Form form2;
        private Button backTo1;
        
        private Label f1l1;
        private Label f1l2;
        private Label f1l3;
        
        public Midlet() {
            Display.init(this);
            
            Font font = null;
            try {
                Resources res = Resources.open("/myres.res");
                //UIManager.getInstance().setThemeProps(res.getTheme("Theme 1"));
                font = res.getFont("Font 1");
            } 
            catch (IOException ex) {
                ex.printStackTrace();
            }
            
            exitCmd = new Command("Exit");
            
            form1 = new Form("Page 1");
            form1.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); //vertical
            
            form1.addCommand(exitCmd);
            form1.addCommandListener(this);
            form1.setBackCommand(exitCmd);
            
            Button btn1 = new Button("to Page 2");
            form1.addComponent(btn1);
            
            this.f1l1 = new Label("from 1 - label 1");
            this.f1l2 = new Label("from 1 - label 2");
            this.f1l3 = new Label("from 1 - label 3");
            form1.addComponent(f1l1);
            form1.addComponent(f1l2);
            form1.addComponent(f1l3);
            
            form2 = new Form("Page 2");
            form2.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); //vertical
            
            backTo1 = new Button("to Page 1");
            form2.addComponent(backTo1);
            
            Container f2c2 = new Container();
            f2c2.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
            for (int i=0; i<20; ++i) {
                Label l = new Label("This is long label #" + i + ", which should have tickering enabled.");
                l.setFocusable(true);
                l.setTickerEnabled(true);
                if (font != null)
                    l.getStyle().setFont(font);
                f2c2.addComponent(l);
            }
            form2.addComponent(f2c2);
            
            btn1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    form2.show();
                }
            });
            backTo1.addActionListener(this);
            
            
            form1.setTransitionInAnimator(
                    CommonTransitions.createSlide(
                        CommonTransitions.SLIDE_HORIZONTAL, true, 1000));
            
            /*form2.setTransitionInAnimator(
                    CommonTransitions.createSlide(
                        CommonTransitions.SLIDE_HORIZONTAL, false, 1000));*/
            form1.setTransitionOutAnimator(
                    CommonTransitions.createSlide(
                        CommonTransitions.SLIDE_HORIZONTAL, false, 1000));
            
        }
        public void startApp() {
            form1.show();
            
            //test
            System.out.println("form1 cc = " + this.form1.getComponentCount()); //always shows 1
            System.out.println("form2 cc = " + this.form1.getComponentCount()); //always shows 1
            
            System.out.println("f1l1 idx = " + this.form1.getComponentIndex(this.f1l1));
            System.out.println("f1l2 idx = " + this.form1.getComponentIndex(this.f1l2));
            System.out.println("f1l3 idx = " + this.form1.getComponentIndex(this.f1l3));
        }
        
        public void pauseApp() {
        }
        
        public void destroyApp(boolean unconditional) {
        }
    
        public void actionPerformed(ActionEvent ae) {
            if (ae.getCommand() == this.exitCmd) {
                notifyDestroyed();
            }
            else if (ae.getComponent() == this.backTo1) {
                this.form1.show();
            }
        }
    }
    ... and output:
    Code:
    form1 cc = 1
    form2 cc = 1
    f1l1 idx = 1
    f1l2 idx = 2
    f1l3 idx = 3
    IDE: NetBeans 7.1.1
    SDK: latest (I hope) S40 2.0
    lwuit: S40-with-themes.jar (also happens with S40-full-touch.jar)

    Is that a bug? Or am I missing something?

  2. #2
    Registered User
    Join Date
    Feb 2013
    Posts
    3

    Re: LWUIT, S40(2.0) - From.getComponentCount() returns 1 always

    Making an educated guess, I think you have a copy/paste issue here:
    System.out.println("form1 cc = " + this.form1.getComponentCount()); //always shows 1
    System.out.println("form2 cc = " + this.form1.getComponentCount()); //always shows 1

    Could you spot the NON difference here? As you can SEE, nothing related to LWUIT ;-)

Similar Threads

  1. Replies: 2
    Last Post: 2012-11-23, 07:39
  2. How to append LWUIT List screen to a LWUIT Form in j2me?
    By pavanragi in forum Mobile Java General
    Replies: 1
    Last Post: 2012-08-06, 07:01
  3. error with LWUIT com.sun.lwuit.impl.midp.CanvasImplementation
    By aymen.ka in forum Mobile Java General
    Replies: 2
    Last Post: 2011-10-27, 11:41
  4. GetRemotePartyInfo returns nothing
    By owcs in forum Symbian
    Replies: 3
    Last Post: 2004-07-13, 09:37

Posting Permissions

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