Search code examples
javajava-melwuit

Draw animation and Images on LWuiT component


I have a problem with understanding how to draw more than one image in container, and how to draw animation on component. First I want to draw for example two images in on component background. here is the code:

public class CountryInteriorContainer extends Component {

private PainterChain backgroundPainterChain;

public CountryInteriorContainer () {
    super();

    backgroundPainterChain = new BackgroundPainterChain(new GroundPainter("CountryBackgroundLand"));
    backgroundPainterChain.addPainter(new CastlePainter("CastleBrown"));

    getStyle().setBgPainter(backgroundPainterChain);
}

}

Here I`m creating painting queue. But there is only one first image on draw on container.

public class CastlePainter extends BasePainter {

public CastlePainter(String imageId) {
    super(imageId);
}

public CastlePainter(Image image) {
    super(image);
}

public void paint(Graphics g, Rectangle rect) {
    g.drawImage(getImage(), rect.getX() + 40, rect.getY());
}

}

BasePainter just initializing image from cache or resources.

Please help me somebody to understand why only first painter works fine. And also how to create animation melodramatically in LWuiT.


Solution

  • I suggest you just override paint() or paintComponent() rather than get into the complexities of a painter. This is even more important when trying to build an animation effect.

    Check out the animations in the LWUIT demo and Codename One demos, you can reproduce that style of animation without much code.