MIDP2.0中Alert的新特性[2]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

            showAlert(a);

            return a;
        }
    }

    // An alert test that displays an alert with
    // a gauge whose value is increased every second.
    // The alert can be dismissed only after the gauge
    // reaches its maximum value.

    public class ProgressAlert extends AlertRunner implements CommandListener,
            Runnable
    {

        private static final int MAX = 10;

        public ProgressAlert(String title)
        {
            super(title);
        }

        public Alert doAlert()
        {
            _gauge = new Gauge(null, false, MAX, 0);
            _gauge.setValue(0);
            _done = false;

            _alert = new Alert(getTitle());
            _alert.setString("Counts to " + MAX
                    + " and then lets you dismiss it");
            _alert.setCommandListener(this);
            _alert.setIndicator(_gauge);

            // Set a _very_ long timeout
            _alert.setTimeout(ONE_SECOND * 3600);

            showAlert(_alert);
            new Thread(this).start();

            return _alert;
        }

        public void commandAction(Command c, Displayable d)
        {
            if (_done || _gauge.getValue() >= MAX)
            {
                showList();
            }
        }

        private void done()
        {
            _alert.addCommand(new Command("Done", Command.OK, 1));
            _done = true;
        }

        // A thread that bumps the value of the counter
        // every second.

        public void run()
        {
            int val = _gauge.getValue();
          
            try
            {
                while (val < MAX)
                {
                    Thread.sleep(ONE_SECOND);
                    _gauge.setValue(++val);
                }
            } catch (InterruptedException e)
            {
            }

本文关键:MIDP2.0中Alert的新特性
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top