aspose file tools*
The moose likes Java Micro Edition and the fly likes Help with switching between forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Help with switching between forms" Watch "Help with switching between forms" New topic
Author

Help with switching between forms

Riamor Von Trapp
Greenhorn

Joined: May 04, 2011
Posts: 12

Hi
I'm hoping someone can help me. I'm a bit confused how to switch between screens. Can someone help me out with a simple sample?
Let say I have an opening Menu with two options. Say Sales and Purchases.

So I have code like


Here's my questions:
1) What code should I add in viewSales and viewPurchases to return to the menu from whence they came?
2) I'm seen different samples, with the commands in a different way. Is it better to declare the commands once, and reuse them? That is, should viewSales and viewPurchases reuse EXIT_CMD and OK_CMD, or should they have their own versions?
First post here, so let me know if I'm missing some detail that is normally required.

Thanks
Soumya Rout
Ranch Hand

Joined: Aug 06, 2009
Posts: 49

1) What code should I add in viewSales and viewPurchases to return to the menu from whence they came?


You need to add Back Command in the midlet and add those commands to the Forms (say viewSales and viewPurchases).
And in the Check for the Back command and switch the display.

LIke :-



Riamor Von Trapp
Greenhorn

Joined: May 04, 2011
Posts: 12

Hi
I added this code in viewSales:


But I'm getting two errors:
1) On the 'this':
method getDisplay in class javax.microedition.lcdui.Display cannot be applied to given types
required: javax.microedition.midlet.MIDlet

2) On the menu
cannot find symbol
symbol: variable menu

I have no idea what to do about problem 1.
For (2), must I add reference to the 'menu' variable somehow?

Thanks for your help!
kumar mdu
Ranch Hand

Joined: Jan 04, 2011
Posts: 59


1. I think, you displaying this by extending the form. 'this' keyword refer to the MIDlet. you create a object of the midlet and passed that value. for eg:


2. If 'menu' is the form, you have to use 'new' operator to display.


have fun

kumar.
Riamor Von Trapp
Greenhorn

Joined: May 04, 2011
Posts: 12

Hi
Thanks everybody for the help.
Here's what I have so far. It may be of use to someone else in the future.

Main Midlet:


Next up, the main menu screen. Pressing the OK button will launch


Sales screen, which has a back button to return to the main menu
Riamor Von Trapp
Greenhorn

Joined: May 04, 2011
Posts: 12

To follow up on the above. I had not realised that you had to store a reference to the prior form. So screenSales has to have private screenMainMenu myMainMenu = null; to able to return to that screen. I think that was the point that confused me the most. I have a dotnet background, where if you exit a form it automatically displays the prior form. Now its a bit clearer.

Anyway, still two more questions.
1) I'd like to add a menu to screenMainMenu. I can't get it to work though.
Code for the menu is here, how would I get this to show when screenMainMenu is launched?
private static final String[] elements = { "Sales", "Purchases" };
private final List menu = new List("Choose", List.IMPLICIT, elements, null);

2) In screenSales, the buttons displayed are actually "Options" and "Back". if I click Options, then I get the Exit button then. How do I keep Exit on the right, with Back in the middle?





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with switching between forms
 
Similar Threads
null pointer exception
my .jar didn't run well
problems with the display MIDP.
nokia 6600 can't select button.......
Display - Best practice