-3

我想在我使用 LWUIT 从 Web 服务加载一些数据时显示对话框,

以下是代码

public class LoaderAnimation extends Container implements Runnable {

private Thread t;
private boolean running = false;

public LoaderAnimation() {
}

public void start() {
    running = true;
    t = new Thread(this);
    t.start();
}

public void run() {
    while (running) {

            // do something
            t.sleep(150);
    }
}

public void stop() {
    running = false;
}
}

现在它运行但调用 Web 服务的代码停止工作会发生什么

这就是它的召唤

public static void showLoaderScreen ()
    {
        dialog = new Dialog();
        dialog.setLayout(new BorderLayout());
        canvas = new LoaderAnimation();
        dialog.addComponent(BorderLayout.CENTER , canvas);
        canvas.start();
        dialog.show();
    }

public static void dismissLoaderScreen ()
{
    canvas.stop();
    dialog.dispose();
}
4

1 回答 1

1

试试这段代码。

private void startLoader() {
    Dialog d = new Dialog();
    d.getStyle().setBgColor(0xffffff);
    d.getStyle().setBgTransparency(255);
    d.show(100, 250, 90, 150, true, false);
    d.setAutoDispose(true);
    try {
        Thread.sleep(30);
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
    d.dispose();
    new Timer().schedule(new TimerTask() {

        public void run() {

            new Loader().start();
        }
    }, 30);
}

Loader 类,我们可以编写解析内容或 Web 服务处理等。

 class Loader extends Thread 

{        public void run() {

            try {

                ServiceTypesScreen st = new ServiceTypesScreen();
                st.init();
            } catch (Exception e) {                    
                e.printStackTrace();
            }

        }
}
于 2012-04-30T06:05:45.830 回答