Exemplo LifeCycleXlet

Esse exemplo exercita as seguintes funcionalidades:

  • Ciclo de vida de Xlet pelo pacote javax.tv.xlet
  • Pintura na tela com Graphics do pacote com.sun.dtv.lwuit..
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 LifeCycleXlet extends Form implements Xlet {

    private static final int STARTED = 0;
    private static final int PAUSED = 1;

    private int appState = -1;
    private XletContext context;
    private Image lifeCyclePaused;
    private Image lifeCycleStarted;

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

            this.lifeCycleStarted = Image.createImage("xlet_state_started.jpg");
            this.lifeCyclePaused = Image.createImage("xlet_state_paused.jpg");
        } catch (Exception e) {
        }
        setTitle("LifeCycle");
    }

    public void startXlet() throws XletStateChangeException {

        System.out.println("**** DEBUG -- startXlet");
        this.appState = STARTED;
        show();
    }

    public void paint(Graphics g) {

        super.paint(g);

        switch (this.appState) {
        case STARTED:
            g.drawImage(this.lifeCycleStarted, 10, 10);
            break;
        case PAUSED:
            g.drawImage(this.lifeCyclePaused, 10, 10);
            break;
        }
    }

    public void pauseXlet() {

        System.out.println("**** DEBUG -- pauseXlet");
        this.appState = PAUSED;
        this.repaint();
    }

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

xlet_state_paused.jpg (17.8 kB) Álan Livio, 16/10/2012 12:13

xlet_state_started.jpg (18.2 kB) Álan Livio, 16/10/2012 12:13