Search code examples
java-memidplcdui

Java ME - Multiple forms, moving from one screen to the next


I am using Java Micro Edition and I am trying to create a simple login form with a record store. When the user enters the details I'd like to check them against the ones stored and then move onto another screen like a welcome area.

I have a feeling it has something to do with the form element and switching between it but I can't seem to get anywhere with google


Solution

  • display is something that should be created in the constructor and also above it i.e.

    public class YourMidlet extends MIDlet implements CommandListener {
    
        private Display display;
        private Form form1;
        private Form form2;
    
        public YourMidlet 
        {
            display = Display.getDisplay(this);
            form 1 = new Form("hello form this is form 1");
            form 2 = new Form("hello form 2");
            display.setCurrent(form1);
        }
    
    }
    

    you then do:

    display.setCurrent(form2);
    

    to switch to form 2