wood burning stoves 2.0*
The moose likes Java Micro Edition and the fly likes Why won't my BACK BUTTON work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Why won Watch "Why won New topic
Author

Why won't my BACK BUTTON work?

ruffy me
Greenhorn

Joined: May 28, 2004
Posts: 4
Here's a short program to take me from a menu list to a form and back.
But my back button won't work. Can you tell me why? Thanks.

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class Testing extends MIDlet implements CommandListener {
private Command exitCommand = new Command("Exit", Command.EXIT, 2);
private Command goCommand = new Command("Go", Command.OK, 2);
private Command backCommand = new Command("Back", Command.BACK, 2);
private Display display;
private Alert resultAlert;
private List list;
public static final String[] items = {"Choice 1", "Choice 2", "Choice 3", "Choice 4"};
public Testing() {
display = Display.getDisplay(this);
list = new List("", List.IMPLICIT, items, null);
list.addCommand(exitCommand);
list.addCommand(goCommand);
list.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
display.setCurrent(list);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
int len, i;
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
} else if (c == goCommand) {
Form resultSet = new Form("Results of Your Search");
String[] strings = {"Here is a page", "written by a sage"};
len = strings.length;
for (i=0; i<len; i++ ) {
resultSet.append(strings[i] + "\n");
}
resultSet.addCommand(backCommand);
display.setCurrent(resultSet);
}
}
}
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Maybe it needs to see a Chiropractor?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Well, because there is no code in the commandAction method to handle the user selecting the command


BACK

public static final int BACK

A navigation command that returns the user to the logically previous screen. The jump to the previous screen is not done automatically by the implementation but by the commandAction provided by the application. Note that the application defines the actual action since the strictly previous screen may not be logically correct.
Value 2 is assigned to BACK.

See Also:



Mark
ruffy me
Greenhorn

Joined: May 28, 2004
Posts: 4
Thanks Mark!
 
Don't get me started about those stupid light bulbs.
 
subject: Why won't my BACK BUTTON work?