Over a million developers have joined DZone.

J2ME - Alert Bloccante

·
// description of your code here


import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;

public class MessageBox extends Alert implements CommandListener
{
	protected Chattando midlet;
	
	private boolean isReady = false;
	
	private Displayable dspBACK;
	
	public MessageBox(String title, String text, AlertType type, Chattando midlet)
	{
		super(title, text, null, type);
		
		this.midlet = midlet;
		
		this.setCommandListener(this);
		this.setTimeout(Alert.FOREVER);
		
		// Display Precedente
		dspBACK = midlet.getDisplay().getCurrent();
		
		// Mostra l'alert
		midlet.getDisplay().setCurrent(this);
		
		// Attendi la conferma di chiusura
		waitForDone();
		
		// Visualizza il precedente Display
		midlet.getDisplay().setCurrent(dspBACK);
	}
	
	private void waitForDone()
	{
		try
		{
			while(!isReady)
			{
				synchronized(this)
				{
					this.wait();
					
				}
			}
		}
		catch(Exception error)
		{
			
		}
	}

	public void commandAction(Command cmd, Displayable dsp)
	{
		if(cmd == Alert.DISMISS_COMMAND)
		{
			isReady = true;
			
			synchronized(this)
			{
				this.notify();
			}			
		}
	}
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}