Hello, I am sending you the code which will give you more information regarding the alert message in java. The example below will give alert message with an image. So, I think this will give you some more knowledge about the alert message.
Code:
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class Alert extends MIDlet implements CommandListener
{
private Display dis;
public Form frm;
private Command ok,cancel,done;
private Image image, image1, image2;
public Alert()
{
frm = new Form("Techarena Alert");
cancel = new Command("Cancel", Command.CANCEL, 2);
ok = new Command("OK", Command.OK, 2);
try
{
image = Image.createImage("/logo.png");
image1 = Image.createImage("/front_left1_bad.png");
image2 = Image.createImage("/Congratulations-1.png");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void startApp()
{
dis = Display.getDisplay(this);
try
{
frm.append(image);
}
catch(Exception e)
{
}
frm.addCommand(cancel);
frm.addCommand(ok);
frm.setCommandListener(this);
dis.setCurrent(frm);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
public void showMsg()
{
Alert success = new Alert("OK", "Alert Message Here!", image2, AlertType.INFO);
success.setTimeout(5000);
success.setImage(image2);
dis.setCurrent(success, frm);
}
public void tryAgain()
{
Alert error = new Alert("Cancel", "Alert Message Here!", image1, AlertType.INFO);
error.setTimeout(5000);
error.setImage(image1);
dis.setCurrent(error, frm);
}
public void commandAction(Command c, Displayable d)
{
String label = c.getLabel();
if(label.equals("Cancel"))
{
tryAgain();
}
else if(label.equals("OK"))
{
showMsg();
}
}
}
Bookmarks