Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
A MIDlet Example to execute Alert Message with an Image 
 

In this "Alert Message" example, you will learn how to send an alert message to user whenever an action is called.

 

A MIDlet Example to execute Alert Message with an Image

                         

In this "Alert Message" example, you will learn how to send an alert message to user whenever an action is called. The example have two different options 1. "ok" and option 2. "Cancel". If user choose the option one "ok" showMsg() method will be called but in case of choosing option two "Cancel" the tryAgain() method will be called.

An alert is a screen that shows message to the user and waits for a given period of time before proceeding to the next Displayable. An alert can contain a text string or an image.

Alert(java.lang.String title):-  This is used to build  new, empty Alert objects with the given title.

Alert(java.lang.Stringtitle, java.lang.StringalertText, javax.microedition.lcdui.ImagealertImage, javax.microedition.lcdui.AlertTypealertType):- we are using this to construct a new Alert object with the given title, content title, string and image, and alert type.

Alert(java.lang.String title, java.lang.String alertText, javax.microedition.lcdui.Image alertImage, javax.microedition.lcdui.AlertType alertType, Style style):- This Constructs a new Alert object with the given title, content string and image, and alert type.

Alert(java.lang.String title, Style style):- Used to create a new, empty Alert object with the given title.

The Alert class have following methods:

  • addCommand(javax.microedition.lcdui.Command cmd)
  • animate(long currentTime, ClippingRegion repaintRegion)
  • commandAction(javax.microedition.lcdui.Command cmd, javax.microedition.lcdui.Displayable thisScreen)
  • createCssSelector() 
  • getDefaultTimeout() 
  • getImage() 
  • getIndicator() 
  • getString() 
  • getTimeout() 
  • getType() 
  • removeCommand(javax.microedition.lcdui.Command cmd)
  • setCommandListener(javax.microedition.lcdui.CommandListener listener)
  • setCurrent(javax.microedition.lcdui.Display display, Alert alert, javax.microedition.lcdui.Displayable nextDisplayable)
  • setImage(javax.microedition.lcdui.Image img) 
  • setImage(javax.microedition.lcdui.Image img, Style style) 
  • setIndicator(Gauge indicator)
  • setIndicator(Gauge indicator, Style style) 
  • setString(java.lang.String str)
  • setString(java.lang.String str, Style style) 
  • setStyle(Style style) 
  • setTimeout(int time) 
  • setType(javax.microedition.lcdui.AlertType type) 
  • showNotify() 

 

 

 

 

Source Code of AlertExample .java

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

public class AlertExample extends MIDlet implements CommandListener{
  private Display display;
  public Form form;
  private Command ok,cancel,done;
  private Image img, imge, img2;
      
  public AlertExample() {
    form = new Form("Roseindia Alert");
    cancel = new Command("Cancel", Command.CANCEL, 2);
    ok = new Command("OK", Command.OK, 2);
    try{
      img = Image.createImage("/logo.png");
      imge = Image.createImage("/front_left1_bad.png");
      img2 = Image.createImage("/Congratulations-1.png");
    }catch(Exception e){
      System.out.println(e.getMessage());
    }    
  }

   public void startApp() {
    display = Display.getDisplay(this);
    try{form.append(img);}catch(Exception e){}
    form.addCommand(cancel);
    form.addCommand(ok);
    form.setCommandListener(this);
    display.setCurrent(form);
  }

  public void pauseApp() {}

  public void destroyApp(boolean unconditional) {
    notifyDestroyed();
  }

  public void showMsg(){
    Alert success = new Alert("OK""Alert Message Here!"
    img2, AlertType.INFO);

    success.setTimeout(5000);
    success.setImage(img2);
    display.setCurrent(success, form);    
  }

  public void tryAgain() {
    Alert error = new Alert("Cancel""Alert Message Here!"
    imge, AlertType.INFO);

    error.setTimeout(5000);
    error.setImage(imge);
    display.setCurrent(error, form);
  }
  
  public void commandAction(Command c, Displayable d) {
    String label = c.getLabel();
    if(label.equals("Cancel")) {
      tryAgain();
    else if(label.equals("OK")) {
      showMsg();
    
  }
}

Download Source Code

                         

» View all related tutorials
Related Tags: c io vi lock this block set frame example ram exam locks e il manual blocks man in as m

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.