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