File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with switching between forms

 
Riamor Von Trapp
Greenhorn
Posts: 12
Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
Java Java ME Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 12
Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic