문제

I want to display among other things a Label containing an Image , the image in this Label is a Timeline :

enter image description here

In fact I got the image from the web : it is an animated gif , so when I added it into the Resource Editor then it was automatically converted into Timeline. Then I added the Label into my 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();
                                                   }
                                                });
        }
}

I included the repaint() method because without it the "please wait" labels are not shown.

So why isn't the Timeline animated ?

도움이 되었습니까?

해결책

You need to read about the EDT. When you are doing actions in call serially you are blocking the event dispatch thread which LWUIT uses to draw and handle events, this is a good thing for small things since you can't have a race condition with LWUIT.

However if you do any lengthy process this blocking would be a problem. Invoke and block is the exact opposite of call serially, it blocks the EDT in a "safe way" and performs an operation on a separate thread that might be very long. For the case of downloading (long io) invokeAndBlock or really just spanning a separate thread is the right thing to do. LWUIT4IO does that seamlessly for you.

다른 팁

I did the same process as you. But I included the image straight in the Form using the resource editor and it works.

Try to do that.

Download the lastest version of LWUIT.(1.5) Create the image as a Timeline In the GUI Builder tab of the resource editor put the image in a Form

I replaced callSerially by invokeAndBlock and the Timeline is animated.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top