LWUIT 1.4:使用Display.callSerially()时,为什么时间轴没有动画?

时间:2011-12-16 06:52:13

标签: java-me lwuit lwuit-resource-editor

我希望显示包含图片的Label,此标签中的图片是Timeline

enter image description here

事实上我从网上获得了图片:它是一个动画gif,所以当我将它添加到资源编辑器中时,它会自动转换为Timeline。然后我将Label添加到我的Form

public class Login extends Ecran implements ActionListener {
...
public Login(SmartPhoneBanking c, Form prevForm) {
   ...
   patientez = new Label((MenuPrincipalForm.r).getImage("roller_fond_blanc")); // r is the LWUIT Resources , you can see the roller_fond_blanc Timeline in the attached image
   patientez.setAlignment(Label.CENTER);
   ...
   cPatienter.addComponent(patientez);
   ...
   }
   ...
   public void actionPerformed(ActionEvent evt) 
   {
        ...
        if (evt.getSource() == validerBtn)
        {
            getTitleComponent().setVisible(false);
            cntnr.removeComponent(cBtn);
            cntnr.removeComponent(libAndFieldContainer);
            removeCommand(listeMenu);
            cntnr.addComponent(cPatienter); // showing the "Please wait" labels and the Timeline
            repaint();
            Display.getInstance().callSerially(new Runnable()
                                               {
                                                   public void run() {
                                                       download();
                                                   }
                                                });
        }
}

我添加了repaint()方法,因为没有它,“请等待”标签不会显示。

那么为什么Timeline没有动画?

3 个答案:

答案 0 :(得分:3)

您需要阅读有关EDT的内容。当您在串行呼叫中执行操作时,您正在阻止LWUIT用于绘制和处理事件的事件派发线程,这对于小事情来说是件好事,因为您不能与LWUIT竞争条件。

但是,如果你做任何冗长的过程,这种阻塞将是一个问题。 Invoke和block与串行调用完全相反,它以“安全的方式”阻塞EDT,并在可能很长的单独线程上执行操作。对于下载(long io)invokeAndBlock的情况,或者实际上只是跨越一个单独的线程是正确的事情。 LWUIT4IO可以无缝地为您完成。

答案 1 :(得分:2)

我做了和你一样的过程。但是我使用资源编辑器将图像直接包含在Form中并且它可以正常工作。

尝试这样做。

下载最新版本的LWUIT。(1.5) 将图像创建为Timeline 在资源编辑器的GUI Builder选项卡中,将图像放在Form

答案 2 :(得分:0)

我将callSerially替换为invokeAndBlock,时间轴已设置动画。