import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
public class TwoAlerts extends MIDlet implements CommandListener {
private Display mDisplay;
private TextBox mTextBox;
private Alert mTimedAlert;
private Alert mModalAlert;
private Command aboutCommand, goCommand, exitCommand;
public TwoAlerts() {
aboutCommand = new Command("About", Command.SCREEN, 1);
goCommand = new Command("Go", Command.SCREEN, 1);
exitCommand = new Command("Exit", Command.EXIT, 2);
mTextBox = new TextBox("TwoAlerts", "", 32, TextField.ANY);
mTextBox.addCommand(aboutCommand);
mTextBox.addCommand(goCommand);
mTextBox.addCommand(exitCommand);
mTextBox.setCommandListener(this);
mTimedAlert = new Alert("Network error", "A network error occurred. Please try again.", null,
AlertType.INFO);
mModalAlert = new Alert("About TwoAlerts",
"TwoAlerts is a simple MIDlet that demonstrates the use of Alerts.", null, AlertType.INFO);
mModalAlert.setTimeout(Alert.FOREVER);
}
public void startApp() {
mDisplay = Display.getDisplay(this);
mDisplay.setCurrent(mTextBox);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == aboutCommand)
mDisplay.setCurrent(mModalAlert);
else if (c == goCommand)
mDisplay.setCurrent(mTimedAlert, mTextBox);
else if (c == exitCommand)
notifyDestroyed();
}
}
|