• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with switching between forms

 
Greenhorn
Posts: 12
Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 49
Netbeans IDE Java ME Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?





 
reply
    Bookmark Topic Watch Topic
  • New Topic