An alert shows data to the user and waits for a period of time before going to the next screen. It can contain text and image. The use of Alert is to inform about errors and other exceptional conditions.

 import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class alertMidlet extends MIDlet implements CommandListener
{
  private Command exitCommand;
  private Command alertCommand;
  private Display display;
  private TextBox tb;

  public alertMidlet() 
  {
    exitCommand = new Command("Exit", Command.EXIT, 1);
    alertCommand = new Command("Alert", Command.SCREEN, 1);
    tb = new TextBox("Alert MIDLET", "Main Screen", 25, 0);
  }

  protected void startApp() 
  {
    tb.addCommand(exitCommand);
    tb.addCommand(alertCommand);
    tb.setCommandListener(this);
    display = Display.getDisplay(this);
    display.setCurrent(tb);
  }  
  
  protected void pauseApp() {}

  protected void destroyApp(boolean bool) {}

  public void commandAction(Command cmd, Displayable disp) 
  {
    if (cmd == exitCommand) {
      destroyApp(false);
      notifyDestroyed();
    }
    else if (cmd == alertCommand)
    {
      Alert at = new Alert("Alert", "Alert Screen", 
                          null, AlertType.INFO);

      display.setCurrent(at);
    }
  }
}

 

 

 

 Related Tips