LWUIT进度条

发布于 2024-11-28 00:07:04 字数 76 浏览 1 评论 0原文

我想在开始时显示一个指示加载应用程序的进度条。

那怎么办呢?我已经创建了一个量规,但我认为它不能以 LWUIT 形式实现。

I want to show a progress bar indicating loading application at the beginning.

How can that be done? I have created a gauge but I think it cannot be implemented in LWUIT form..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

压抑⊿情绪 2024-12-05 00:07:04

根据我的评论,您可以使用进度栏。您还可以使用 滑块组件 代替在 LWUIT 中显示进度条。

Based on my comment, You can use progress bar. And also you can use slider component for instead of showing progress bar in LWUIT.

明媚殇 2024-12-05 00:07:04

最好的方法是使用画布。您可以在所有应用程序中重用该类,而且非常高效。创建一个类,例如名为 Splash:

public class Splash extends Canvas {

private final int height;
private final int width;
private int current = 0;
private final int factor;
private final Timer timer = new Timer();
Image AppLogo;
MayApp MIDlet;

/**
 *
 * @param mainMIDlet
 */
public Splash(MyApp mainMIDlet) {

    this.MIDlet = mainMIDlet;
    setFullScreenMode(true);
    height = getHeight();
    width = this.getWidth();
    factor = width / 110;
    repaint();
    timer.schedule(new draw(), 1000, 01);
}

/**
 *
 * @param g
 */
protected void paint(Graphics g) {
    try {//if you want to show your app logo on the splash screen
        AppLogo = javax.microedition.lcdui.Image.createImage("/appLogo.png");
    } catch (IOException io) {
    }
    g.drawImage(AppLogo, getWidth() / 2, getHeight() / 2, javax.microedition.lcdui.Graphics.VCENTER | javax.microedition.lcdui.Graphics.HCENTER);
    g.setColor(255, 255, 255);
    g.setColor(128, 128, 0);//the color for the loading bar
    g.fillRect(30, (height / 2) + 100, current, 6);//the thickness of the loading bar, make it thicker by changing 6 to a higher number and vice versa
}

private class draw extends TimerTask {

    public void run() {
        current = current + factor;
        if (current > width - 60) {
            timer.cancel();
            try {
                //go back to your midlet or do something
            } catch (IOException ex) {
            }
        } else {
            repaint();
        }
        Runtime.getRuntime().gc();//cleanup after yourself
    }
}

}

的类,并在您的 MIDlet 中:

public class MyApp extends MIDlet {

Splash splashScreen = new Splash(this);

    public MyApp(){
}

public void startApp(){

    try{
        Display.init(this);
        javax.microedition.lcdui.Display.getDisplay(this).setCurrent(splashScreen);
        //and some more stuff
        } catch (IOException ex){}
}
//continue

The best way is to use canvas. You can reuse the class in all your apps and it is very efficient. Create a class, say like a class named Splash:

public class Splash extends Canvas {

private final int height;
private final int width;
private int current = 0;
private final int factor;
private final Timer timer = new Timer();
Image AppLogo;
MayApp MIDlet;

/**
 *
 * @param mainMIDlet
 */
public Splash(MyApp mainMIDlet) {

    this.MIDlet = mainMIDlet;
    setFullScreenMode(true);
    height = getHeight();
    width = this.getWidth();
    factor = width / 110;
    repaint();
    timer.schedule(new draw(), 1000, 01);
}

/**
 *
 * @param g
 */
protected void paint(Graphics g) {
    try {//if you want to show your app logo on the splash screen
        AppLogo = javax.microedition.lcdui.Image.createImage("/appLogo.png");
    } catch (IOException io) {
    }
    g.drawImage(AppLogo, getWidth() / 2, getHeight() / 2, javax.microedition.lcdui.Graphics.VCENTER | javax.microedition.lcdui.Graphics.HCENTER);
    g.setColor(255, 255, 255);
    g.setColor(128, 128, 0);//the color for the loading bar
    g.fillRect(30, (height / 2) + 100, current, 6);//the thickness of the loading bar, make it thicker by changing 6 to a higher number and vice versa
}

private class draw extends TimerTask {

    public void run() {
        current = current + factor;
        if (current > width - 60) {
            timer.cancel();
            try {
                //go back to your midlet or do something
            } catch (IOException ex) {
            }
        } else {
            repaint();
        }
        Runtime.getRuntime().gc();//cleanup after yourself
    }
}

}

and in your MIDlet:

public class MyApp extends MIDlet {

Splash splashScreen = new Splash(this);

    public MyApp(){
}

public void startApp(){

    try{
        Display.init(this);
        javax.microedition.lcdui.Display.getDisplay(this).setCurrent(splashScreen);
        //and some more stuff
        } catch (IOException ex){}
}
//continue
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文