My Alert does not show

Why does not my Alert pop up? My intention is that the user needs to confirm the information before he/she can continue

Alert a =new Alert(null,"Your changes has been saved", null, AlertType.CONFIRMATION);

a.setTimeout(Alert.FOREVER);

midlet.getDisplay().setCurrent(a);

[354 byte] By [sandsatera] at [2007-11-27 0:46:04]
# 1
have you tried this?Display.getDisplay(yourMIDlet).setCurrent(yourAlert,yourDisplayable)
suparenoa at 2007-7-11 23:11:51 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
try this...Alert a = new Alert("", "Your changes has been saved", null, AlertType.CONFIRMATION);
ParagPatila at 2007-7-11 23:11:51 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

> Alert a = new Alert(null, "Your changes has

> been saved", null, AlertType.CONFIRMATION);

> a.setTimeout(Alert.FOREVER);

> midlet.getDisplay().setCurrent(a);

What is "midlet" refers to? Is it a reference to an object of your midlet class? In that case what is getDisplay()? Is it a method in your midlet? It should not be.. as it is a static method of Display class.

The actual code will be like this:

import javax.microedition.lcdui.*;

import javax.microedition.midlet.MIDlet;

public class myAlert extends MIDlet {

protected void startApp() {

Display display=Display.getDisplay(this);

Alert a = new Alert(null, "Your changes has been saved", null, AlertType.CONFIRMATION);

a.setTimeout(Alert.FOREVER);

display.setCurrent(a);

}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {

}

}

diptaPBa at 2007-7-11 23:11:51 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

I think I do like you guys show.

midlet refers to my midlet class, and in it a method like this exists. Thats why I think this would work but it does not

public Display getDisplay()

{

return Display.getDisplay(this);

}

sandsatera at 2007-7-11 23:11:51 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

Ok, here comes a bigger piece of code!

My start class, the MIDLet has a reference that is passed around in the application when you switch different things on the screen.

In this MIDLet class there are a bunch of alert-methods that work like wrappers for launching an Alert.

For example we have a private method (it is called from a public one that pretty much just call this one)

private void alert(String text, AlertType type, boolean blocking) {

Alert alert = new Alert(null,text,null,type);

alert.setTimeout(Alert.FOREVER);

Displayable current;

if(blocking) {

final Object alertLock = new Object();

alert.setCommandListener(new CommandListener() {

public void commandAction(Command cmd, Displayable disp) {

synchronized (alertLock) {

alertLock.notify();

}

}

});

//Store current and show alert

current = waitUntilDisplayIsNotAlert();

setDisplay(alert);

//Wait for user to select

synchronized (alertLock) {

try {

alertLock.wait();

} catch (InterruptedException e) {

e.printStackTrace();

}

}

//Return to previous display

setDisplay(current);

} else {

current = waitUntilDisplayIsNotAlert();

getDisplay().setCurrent(alert, current);

}

current = null;

}

If blocking = true it hangs, and if blocking = false it is never shown.

private synchronized Displayable waitUntilDisplayIsNotAlert() {

while(getDisplay().getCurrent() instanceof Alert) {

try {

Thread.sleep(100);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

return getDisplay().getCurrent();

}

Message was edited by:

sandsater

sandsatera at 2007-7-11 23:11:51 > top of Java-index,Java Mobility Forums,Java ME Technologies...