DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

J2ME - Alert Bloccante

Snippets Manager user avatar by
Snippets Manager
·
Feb. 24, 07 · · Code Snippet
Like (0)
Save
Tweet
663 Views

Join the DZone community and get the full member experience.

Join For Free
// 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();
			}			
		}
	}
}

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • After COVID, Developers Really Are the New Kingmakers
  • Top 20 Git Commands With Examples
  • Upsert in SQL: What Is an Upsert, and When Should You Use One?
  • Making Your SSR Sites 42x Faster With Redis Cache

Comments

Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo