延迟显示管理器中的字段(黑莓)

发布于 2024-11-08 11:15:10 字数 216 浏览 0 评论 0原文

我有一个循环向管理器添加字段,我试图延迟每个字段绘制到屏幕上之间的时间。我一直在尝试下面的代码,但它只是在所有字段都添加到其中后才绘制管理器。 这可能吗?

manager.add(field);
manager.invalidate();//force a repaint of the manager
Thread.sleep(1000);

谢谢

I have a loop adding fields to a manager, I am trying to delay the time between when each field is painted onto the screen. I have been trying below code but it just paints the manager when all fields have been added to it.
Is this possible ?

manager.add(field);
manager.invalidate();//force a repaint of the manager
Thread.sleep(1000);

Thanks

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

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

发布评论

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

评论(1

一指流沙 2024-11-15 11:15:10

无效并不一定会强制绘制,它只是表示在下一次绘制时需要重新绘制字段(或您的情况下的管理器)。这是一个微妙的差异,但可能会引起混乱。您可能想要尝试的是调用 Screen.doPaint() ,这将强制重新绘制整个屏幕。另外,将 sleep() 放在事件线程中不会有帮助,因为绘画也是在同一个线程上完成的。

如果您尝试在第二次延迟的情况下按顺序向管理器添加字段,则应将此逻辑放入其自己的线程中,并在执行时执行 synchronized(UiApplication.getEventLock()){//add fields}调用manager.add(field)。然后你可以调用你的 Thread.sleep(1000) 来正确地延迟显示。另外,就像一些添加的信息一样,调用 add() 本质上会导致 invalidate() 调用,因此您不需要添加它。这是添加第二次延迟的简单示例

protected void addDelayedFields() {
    Thread t = new Thread( new Runnable() {
        public void run() {
            for(int i=0;i<SOME_LIMIT;i++) {
                synchronized(UiApplication.getEventLock()) {
                    manager.add(new LabelField(i.toString());
                }
                try{
                    Thread.sleep(1000);
                }
                catch(Exception e){ }
            }
        }
    });
    t.start();
}

绘制应该在 add() 之后发生,但如果没有发生,您也可以调用 yourScreen.doPaint()

Invalidate doesn't necessarily force a paint, it simply says that on the next paint the Field (or Manager in your case) needs to be redrawn. It's a subtle difference but it could be causing the confusion. What you might want to try is calling Screen.doPaint(), which will force the entire screen to redraw. Also, putting the sleep() in your Event Thread won't help, because painting is also done on the same Thread.

If you are trying to sequentially add Fields to your Manager with this second delay, you should put this logic in its own Thread and do synchronized(UiApplication.getEventLock()){//add fields} when you call manager.add(field). Then you can call your Thread.sleep(1000) to correctly have the delay in displaying. Also, just as a some added info, calling add() inherently causes an invalidate() call, so you don't need to add it. Here's a simple example of the second delay in adding

protected void addDelayedFields() {
    Thread t = new Thread( new Runnable() {
        public void run() {
            for(int i=0;i<SOME_LIMIT;i++) {
                synchronized(UiApplication.getEventLock()) {
                    manager.add(new LabelField(i.toString());
                }
                try{
                    Thread.sleep(1000);
                }
                catch(Exception e){ }
            }
        }
    });
    t.start();
}

The painting should occur after the add(), but if it doesn't you can also make a call to yourScreen.doPaint()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文