Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic J2ME Question

 
Reinhardt Christiansen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to understand the proper technique for dismissing a form when I am done with it.

My MIDlet, whose main class is MemberManager, displays a list of members of an organization; the user can scroll this List. In addition, it provides Commands for Adding new members, Changing data for members, and Deleting members. When they choose to Add a member, a Form containing input text fields is displayed; the user enters data into those fields and presses one of two buttons: Insert or Cancel. Insert means the user wants to add the data to the record store and Cancel means that the user has changed his mind and wants to return to the member list without adding the new data.

In my code, the logic for that displays the Add form and handles its two
commands are in a separate class, MemberAddForm. In the button handling logic in MemberAddForm, the logic for the Cancel button simply says to display an information Alert that says "Insert cancelled" for 5000 milliseconds, then return, i.e. pass control back to the class that invokes MemberAddForm, namely MemberManager. At least, that is what I would LIKE to happen ;-) Here is the actual code:

if (label.equals(CANCEL_INSERT_TEXT)) {
System.out.println(CLASS_NAME + "." + METHOD_NAME + " - User chose " +
CANCEL_INSERT_TEXT + ".");
String msg = "Insert Cancelled.";
Alert cancelled = new Alert("Action", msg, null, AlertType.INFO);
cancelled.setTimeout(5000); //milliseconds
display.setCurrent(cancelled);
return;
}

This code works but after the return is executed, I am still on the Form
that is displayed by the MemberAddForm class, not the newly refreshed
memberList from the MemberManager class. What do I need to do to end the MemberAddForm gracefully and get back to the member list in the
MemberManager class? I'm looking for something like the dispose() method that I use when I write dialogs in J2SE.

My main class, MemberManager class, extends MIDlet. My supporting class,
MemberAddForm, extends Form. Is that the right approach? I wondered if I should have MemberAddForm extend MIDlet and then have MemberManager instantiate it but the API for MIDlet says MIDlets should never attempt to create other MIDlets. I'm a little confused because my approach in J2SE would be to make MemberAddForm a dialog that is initiated by a Frame but J2ME doesn't seem to have the concept of a
dialog.

Can anyone shed some light on this for me?
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can require the user to dismiss the "cancelled" alert box. And in that "dismiss" command callback, you can set the display to your new screen.
 
Tomas Conway
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can specify the Displayable you want to go to after the Alert is dismissed by providing a second parameter in 'Display.setCurrent()'

For example if you pass a MemberManager reference to MemberAddForm (call it 'memberManager' for example), then you can use the following line to show the alert for the specified time, and then control will pass to MemberManager.



Look up the two parameter version of Display.setCurrent() in the API.
 
Reinhardt Christiansen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both very much for your reply! (Also, forgive my delay in responding: I had problems logging back in until I discovered that I had originally posted in Opera; no wonder IE wouldn't let me log in since it couldn't find my login cookie ;-)

Tomas, I used your suggestion and it worked very well. Michael, I wanted to try your approach but I couldn't quite figure out how the code would look. Could you possible give me a code fragment that demonstrates your callback technique? I'd really like to know your technique too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic