Exemple ImageXlet

Esse exemplo exercita o uso das funcionalidades:

  • Ciclo de vida de Xlet pelo pacote javax.tv.xlet
  • Pintura na tela com Graphics do pacote com.sun.dtv.lwuit..
  • Animação de Componente lwuit.
import java.io.IOException;

import javax.tv.xlet.Xlet;
import javax.tv.xlet.XletContext;
import javax.tv.xlet.XletStateChangeException;

import com.sun.dtv.lwuit.Form;
import com.sun.dtv.lwuit.Graphics;
import com.sun.dtv.lwuit.Image;

public class ImageXlet extends Form implements Xlet {

    private XletContext context;
    private Image image;

    private int step = 8;
    private int ix = 100;
    private int iy = 100;
    private int idx = 1;
    private int idy = 1;

    public void initXlet(XletContext ctx) throws XletStateChangeException {
        System.out.println("**** DEBUG -- initXlet");
        this.context = ctx;
        setTitle("Image");
    }

    public void startXlet() throws XletStateChangeException {
        System.out.println("**** DEBUG -- startXlet");
        try {
            image = Image.createImage("test.png");
        } catch (IOException e) {
        }
        registerAnimated(this);
        show();
    }

    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(image, ix, iy);
    }

    public boolean animate() {
        ix = ix + idx*step;
        return true;
    }

    public void pauseXlet() {
    }

    public void destroyXlet(boolean unconditional) throws XletStateChangeException {
        context.notifyDestroyed();
    }

}

test.png (16.7 kB) Álan Livio, 16/10/2012 12:14