MIDlet Design Question

R

Rhino

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 which the user can scroll. In addition, it provides buttons
or menu items to Add new members, Change data for members, and Delete
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
buttons 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
display the memberList (a reference to the memberList was passed to the
MemberAddForm class). 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 or should
MemberAddForm also extend MIDlet? Is that my problem? If MemberAddForm also
extended MIDlet, I could destroy it when I am done with it. 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?

--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
 
J

JScoobyCed

Rhino said:
...

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;
}

Hi,

the code above siply says how to "dispose" of the Alert, not how to
display the current form. The Display class also accept another
setCurrent(Alert, Displayable) method. When the Alert disappear, the
second parameter will be set as current screen. If your second parameter
is the Displayable object that render the member list, then you will
have the expected result. But as I understand, the MemberManager is your
MIDlet, and it doesn't subclass Displayable.

My main class, MemberManager class, extends MIDlet. My supporting class,
MemberAddForm, extends Form. Is that the right approach or should
MemberAddForm also extend MIDlet? Is that my problem? If MemberAddForm also
extended MIDlet, I could destroy it when I am done with it. 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?

Well, I wouldn't recommand the MIDlet (MemberManager) to be the class
that displays the list of member. Instead, it would be preferrable to
have a subclass of Form as well. In the MIDlet, just call
display.setCurrent(MemberManager) at startup, or even better, on the
action of a button. And then, for your alert, you can do:
display.setCurrent(canceled,memberManager);
Note that this will work only if canceled has no CommandListener except
the default one (that is, you don't explicitly provide a CommandListener
on the Alert).

JScoobyCed
 
D

Darryl L. Pierce

Rhino said:
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;
}

Uh uh. Your should be calling the form of setCurrent() that takes both an
Alert *and* a Displayable. That tells the system what Displayable to show
*after* the Alert has expired or been dismissed.

if(label.equals(CANCEL_INSERT_TEXT))
{
Alert cancelled = new Alert("Action",msg,null,AlertType.INFO);
cancelled.setTimeout(5000);
Display.getDisplay(myMidlet).setCurrent(cancelled,theNextDisplayable);
}

--
/**
* @author Darryl L. Pierce <[email protected]>
* @see The Infobahn Offramp <http://mcpierce.multiply.com>
* @quote "Lobby, lobby, lobby, lobby, lobby, lobby..." - Adrian Monk
*/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,282
Latest member
RoseannaBa

Latest Threads

Top