Simplest way to Display Pregressing bar - BlackBerry Java programming

You can create the instance of the  ProgressBar and you can pass the time out and display messages to progressing bar.

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.GaugeField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.DialogFieldManager;
import net.rim.device.api.ui.container.PopupScreen;

public class ProgressBar extends Thread 
{
    private int maximum, timeout;
    private boolean useful;
    private PopupScreen popup;
    private GaugeField gaugeField;
    public ProgressBar(String title, int maximum, int timeout)
    {
        this.maximum = maximum;
        this.timeout = timeout;
        DialogFieldManager manager = new DialogFieldManager();
        popup = new PopupScreen(manager);
        gaugeField = new GaugeField(null, 1, maximum, 1, GaugeField.NO_TEXT);
        manager.addCustomField(new LabelField(title));
        manager.addCustomField(gaugeField);
    }

    public void run() 
    {
        useful = true;
        UiApplication.getUiApplication().invokeLater(new Runnable() 
        {
            public void run() 
            {
                UiApplication.getUiApplication().pushScreen(popup);
               
            }
        });

        int iterations = 0;
        while (useful)
        {
            try 
            {
                Thread.sleep(timeout);
            } 
            catch (Exception e) 
            {
               
            }
            if (++iterations > maximum)
            {
                useful =false;
                UiApplication.getUiApplication().invokeLater(new Runnable() 
                {
                    public void run() 
                    {
                        Dialog.alert("Successfully  Completed");
                         System.exit(0);
                    }
                });
               
                iterations = 1;
            }
            gaugeField.setValue(iterations);
        }

        if (popup.isDisplayed()) 
        {
            UiApplication.getUiApplication().invokeLater(new Runnable() 
            {
                public void run() 
                {
                    UiApplication.getUiApplication().popScreen(popup);
                }
            });
        }
    }

    public synchronized void remove() 
    {
        useful = false;
    }
}

2 comments:

  1. Sourcecode is very interesting, I want to try it, thank you for this code.

    ReplyDelete
  2. Wow, this post is pleasant, my sister is analyzing such things, therefore I am going
    to inform her.
    My webpage long hairstyles

    ReplyDelete

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...