Exemplo LabelXlet

Esse exemplo exercita o uso das seguintes funcionalidades:

  • Ciclo de vida de Xlet pelo pacote javax.tv.xlet
  • Pintura na tela com Graphics do pacote com.sun.dtv.lwuit..
  • Captura de eventos de eventos com.sun.dtv.ui.event.KeyEvent.
  • Widigt gráfico LWUIT: Label.
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.Image;
import com.sun.dtv.lwuit.Label;
import com.sun.dtv.lwuit.geom.Dimension;
import com.sun.dtv.lwuit.layouts.BorderLayout;

public class LabelXlet extends Form implements Xlet {

    private XletContext context;

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

    public void startXlet() throws XletStateChangeException {
        System.out.println("**** DEBUG -- startXlet");
        this.setX(100);
        this.setY(100);
        this.setSize(new Dimension(400, 200));

        Label label = new Label("");
        String text = "Ginga is Great!";
        label.setText(text);
        try {
            label.setIcon(Image.createImage("./test.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        addComponent(BorderLayout.NORTH, label);

        show();
    }

    public void pauseXlet() {
    }

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

}

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