Uma alerta mostra dados ao usuário e espera um período de tempo antes de ir à tela seguinte. Pode conter texto e imagem. O uso de alerta serve para informar sobre erros e outras condições diferentes.


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