we can add Command to the alert
and it goes out after some time plz have a look
Can Any one give how to make it like AlertType FOREVER
regards
Arun Gupta
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hello;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
/**
*
* @author Arun Gupta
*/
class CanvasDisplayable extends Canvas implements CommandListener
{
public Alert alert;
Command showalert,close;
public boolean show = false;
MIDlet mid;
public CanvasDisplayable(MIDlet mid)
{
alert = new Alert("Alert","Arun",null,AlertType.CONFIRMATION);
showalert = new Command("showalert",Command.SCREEN,1);
close = new Command("Close",Command.SCREEN,1);
alert.setCommandListener(this);
this.addCommand(showalert);
setCommandListener(this);
this.mid = mid;
}
protected void paint(Graphics graphics)
{
graphics.drawRect(0, 0, this.getWidth(),this.getHeight());
graphics.setColor(255);
graphics.fillRect(0, 0, this.getWidth(),this.getHeight());
graphics.drawString("Akdajd", UP, UP,Graphics.LEFT|Graphics.TOP);
if(show == true)
{
show = false;
if(close!=null)
alert.addCommand(close);
Display.getDisplay(mid).setCurrent(alert);
}
}
public void commandAction(Command cmd, Displayable arg1) {
System.out.println(cmd.getLabel());
if(cmd.getLabel().equals("showalert"))
{
show = true;
repaint();
}
else if (cmd.getLabel().equals("Close"))
{
Display.getDisplay(mid).setCurrent(this);
}
}
}

Reply With Quote


