Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

J2ME - Alert Bloccante

// description of your code here

   1  
   2  import javax.microedition.lcdui.Alert;
   3  import javax.microedition.lcdui.AlertType;
   4  import javax.microedition.lcdui.Command;
   5  import javax.microedition.lcdui.CommandListener;
   6  import javax.microedition.lcdui.Displayable;
   7  
   8  public class MessageBox extends Alert implements CommandListener
   9  {
  10  	protected Chattando midlet;
  11  	
  12  	private boolean isReady = false;
  13  	
  14  	private Displayable dspBACK;
  15  	
  16  	public MessageBox(String title, String text, AlertType type, Chattando midlet)
  17  	{
  18  		super(title, text, null, type);
  19  		
  20  		this.midlet = midlet;
  21  		
  22  		this.setCommandListener(this);
  23  		this.setTimeout(Alert.FOREVER);
  24  		
  25  		// Display Precedente
  26  		dspBACK = midlet.getDisplay().getCurrent();
  27  		
  28  		// Mostra l'alert
  29  		midlet.getDisplay().setCurrent(this);
  30  		
  31  		// Attendi la conferma di chiusura
  32  		waitForDone();
  33  		
  34  		// Visualizza il precedente Display
  35  		midlet.getDisplay().setCurrent(dspBACK);
  36  	}
  37  	
  38  	private void waitForDone()
  39  	{
  40  		try
  41  		{
  42  			while(!isReady)
  43  			{
  44  				synchronized(this)
  45  				{
  46  					this.wait();
  47  					
  48  				}
  49  			}
  50  		}
  51  		catch(Exception error)
  52  		{
  53  			
  54  		}
  55  	}
  56  
  57  	public void commandAction(Command cmd, Displayable dsp)
  58  	{
  59  		if(cmd == Alert.DISMISS_COMMAND)
  60  		{
  61  			isReady = true;
  62  			
  63  			synchronized(this)
  64  			{
  65  				this.notify();
  66  			}			
  67  		}
  68  	}
  69  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS