java-memidplcdui

I want to add a progress bar in j2me application


I want to add a progress bar in j2me application that shows the busy process.

I am doing this using alert adding gauge as indicator but it disappears on button click.


Solution

  • If you do not want to go with LCDUI Alert or LWUIT you can use Canvas. I have shared a very simple sample at http://smallandadaptive.blogspot.com.br/2009/09/adding-simple-progress-bar.html Full text below:

    A progress bar is a visual representation of a Real Number between zero and one or a percentage between 0% and 100%.

    Below is a method for drawing a simple progress bar:

    
        /**
         * @param g Graphics
         * @param x
         * @param y
         * @param w width
         * @param h height
         * @param p part between zero and total
         * @param t total
         */
        void fillProgressBar (Graphics g, int x, int y, int w, int h, int p, int t) {
          g.drawRect(x, y, w, h);
          // p will receive the pixel width of the proportion: part / total
          p = (p * w) / t;
          g.fillRect(x, y, p, h);
        }