Exemplo ButtonsXlet

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..
  • Widigt gráfico LWUIT: Button.
import javax.tv.xlet.Xlet;
import javax.tv.xlet.XletContext;
import javax.tv.xlet.XletStateChangeException;

import com.sun.dtv.lwuit.Button;
import com.sun.dtv.lwuit.Form;
import com.sun.dtv.lwuit.events.ActionEvent;
import com.sun.dtv.lwuit.events.ActionListener;
import com.sun.dtv.lwuit.geom.Dimension;
import com.sun.dtv.lwuit.layouts.BorderLayout;

public class ButtonsXlet extends Form implements Xlet{

    private XletContext context;    
    Button bNorth;
    Button bCenter;

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

        setTitle("Buttons");

        this.context = ctx;
    }

    public void startXlet() throws XletStateChangeException {
        System.out.println("**** DEBUG -- startXlet");
        this.setSize(new Dimension(400, 200));
        bCenter = new Button("Center");
        addComponent(BorderLayout.CENTER, bCenter);
        bCenter.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {
                bCenter.setText("Center pushed");

            }
        });

        show();
        bNorth = new Button("North");
        bNorth.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {
                bNorth.setText("North pushed");

            }
        });
        addComponent(BorderLayout.NORTH, bNorth);

        repaint();
    }

    public void pauseXlet() {
    }

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

}