Two Alerts : Alert « J2ME « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » J2ME » AlertScreenshots 
Two Alerts
Two Alerts

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


           
       
Related examples in the same category
1.An example MIDlet with simple Alert UI component containing an Image.An example MIDlet with simple Alert UI component containing an Image.
2.High-Level Display Screens : AlertHigh-Level Display Screens : Alert
3.Animated TimerAnimated Timer
4.Login MidletLogin Midlet
5.Multi Alert
6.Modal AlertModal Alert
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.