0

i want to make a basic mobile app using LWUIT, but am having difficulties using forms,i don't know how to close a form to go to the form from which i opened it.

So basically having trouble switching between forms,so i need some help regarding that and also is there any better alternative present than using a form to display components on the screen

Any help would be much appreciated

   Form a = new Form (); 
   FlowLayout exampleLayout = new FlowLayout(); 
   final Button button  = new Button("1");

    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
             Form b = new Form ();
            //how to get back form this form b to form a 
        }
    });

i don't know how to get back from form b to form a there is no close method or dispose() method present for a Form

user2497398
  • 61
  • 1
  • 1
  • 4

3 Answers3

2

There is no dispose method for Forms in LWUIT. You simply call the show() method of another Form to replace the old one. Since LWUIT is built to work with little memory, it disposes its references to the old Form before replacing it with the new one. If the "new" Form is just an old one accessed with the Back button, you can use showBack(). This method reverses the Form transition so that it appears to "get back into view". Here's an example.

public void showA(boolean back) {
    Form a = new Form (); 
    a.setTitle("AAAA");
    FlowLayout exampleLayout = new FlowLayout(); 
    final Button button  = new Button("1");

     button.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
              showB(false);
         }
     });
     a.addComponent(button);
     a.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 1000));
     if (back) {
         a.showBack();
     } else {
        a.show();
     }
}

public void showB(boolean back) {
    Form b = new Form ();
    b.setTitle("BBBBB");
    FlowLayout exampleLayout = new FlowLayout(); 
    final Button button  = new Button("1");
    Command c = new Command("Back") {
        public void actionPerformed(ActionEvent evt) {
            showA(true);
        }
    };
    b.setBackCommand(c);
    b.addCommand(c);


    button.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
              showA(false);
         }
     });
     b.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 1000));
     b.addComponent(button);
     if (back) 
         b.showBack();
     else
         b.show();
}

public void startApp() {
    Display.init(this);
    showA(false);
}
igordsm
  • 464
  • 2
  • 8
1

I think, we don't have to close the form. We have only to show one form at a time. example:

a.show();

when you have a button in form a which trigger b.show(); you can change the form to b form.

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
mico wendy
  • 46
  • 3
0

In first you need to add all components to form.

for run some forms the best way is to work with threads. In LWUIT you have built-in threads. you can use them like that:

Display.getInstance().callSerially(new Runnable() {
            public void run() {
                .....
            }
});

of course you must call show() function to display forms

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
neb1
  • 209
  • 1
  • 12