Pizzariaxlet

PizzariaXlet

Autores: Diogo Henrique, Aquiles Burlamaqui

PizzariaXlet.java

import org.havi.ui.*;
import javax.tv.xlet.*;
 
public class PizzariaXlet implements Xlet {
    private XletContext context;
    private HScene scene;
    public PizzariaXlet() {
    }
    public void initXlet(XletContext xletContext)
            throws XletStateChangeException {
        System.out.println("initXlet");
        context = xletContext;
    }
    public void startXlet() throws XletStateChangeException {
        System.out.println("startXlet - 0");
        HSceneFactory hsceneFactory = HSceneFactory.getInstance();
        scene = hsceneFactory.getFullScreenScene(HScreen.getDefaultHScreen()
                .getDefaultHGraphicsDevice());
        scene.setSize(640, 540);
        System.out.println("startXlet - 1");
        scene.setLayout(null);
        scene.setVisible(true);
 
        TelaInicial telaInicial = new TelaInicial(scene);
        telaInicial.init();
    }
    public void pauseXlet() {
    }
    public void destroyXlet(boolean flag) throws XletStateChangeException {
        System.out.println("destroyXlet");
        context.notifyDestroyed();
    }
}

TelaInicial.java

import org.dvb.event.*;
import org.havi.ui.*;
import org.havi.ui.event.*;
 
public class TelaInicial implements UserEventListener {
    private HScene scene;
    private EventManager em;
    private Imagens imagens;
    private HIcon hi;
    public TelaInicial(HScene scene){
        System.out.println("TelaInicial - 0");
        this.scene=scene;
        em = EventManager.getInstance();
        imagens = new Imagens();
 
    }
    public void init() {
        System.out.println("TelaInicial init() - 0");
            hi = new HIcon(imagens.carregarImagem(Imagens.telaInicial),0,0,640,540);
        System.out.println("TelaInicial init() - 1");
        UserEventRepository uer = new UserEventRepository("TelaInicial");
 
        uer.addKey(HRcEvent.VK_ENTER);
        em.addUserEventListener(this,uer);
        System.out.println("TelaInicial init() - 2 ,hi:"+hi);
        scene.add(hi);
        System.out.println("TelaInicial init() - 3");
        scene.repaint();
    }
    public void clear() {
        scene.removeAll();
        scene.repaint();
        em.removeUserEventListener(this);
    }
    public void userEventReceived(UserEvent e) 
    {
        int type =e.getType();
        int code = e.getCode();
 
        if(type==HKeyEvent.KEY_PRESSED) {
 
            if (code== HRcEvent.VK_ENTER) {
                this.clear();
                TelaPizza tela = new TelaPizza(scene);
                tela.init();
            }                    
        }
    }
}

TelaPizza.java

import java.awt.TextField;
import org.dvb.event.*;
import org.havi.ui.*;
import org.havi.ui.event.*;
 
public class TelaPizza implements UserEventListener {
    private HScene scene;
    private EventManager em;
    private TextField tfNome, tfLog, tfCEP, tfBairro, tfPizza, tfApt, tfCidade,tfObs;
 
    Imagens imagens;
    HIcon hi;
 
    public TelaPizza(HScene scene){
        this.scene=scene;
        em = EventManager.getInstance();
        imagens = new Imagens();
 
        tfLog = new TextField();
        tfLog.setSize(167, 25);
        tfLog.setLocation(162, 400);
 
        tfNome = new TextField();
        tfNome.setSize(227, 25);
        tfNome.setLocation(101, 365);                               
 
        tfApt = new TextField();
        tfApt.setSize(156, 25);
        tfApt.setLocation(174, 435);
 
        tfCidade = new TextField();
        tfCidade.setSize(213, 25);
        tfCidade.setLocation(117, 474);
 
        tfBairro = new TextField();
        tfBairro.setSize(202, 25);
        tfBairro.setLocation(408, 365);
 
        tfPizza = new TextField();
        tfPizza.setSize(212, 25);
        tfPizza.setLocation(398,435);
 
        tfCEP = new TextField();
        tfCEP.setSize(225, 25);
        tfCEP.setLocation(385, 400);
 
        tfObs = new TextField();
        tfObs.setSize(213, 25);
        tfObs.setLocation(397, 474);
    }
    public void init() {
 
        hi = new HIcon(imagens.carregarImagem(Imagens.telaPizza),0,0,640,540);
 
        UserEventRepository uer = new UserEventRepository("TelaPizza");
 
        uer.addKey(HRcEvent.VK_ENTER);
        uer.addAllArrowKeys();
        em.addUserEventListener(this,uer);
 
        scene.add(hi);
        scene.repaint();
        scene.add(tfNome);
        scene.add(tfLog);
        scene.add(tfApt);
        scene.add(tfCidade);
        scene.add(tfBairro);
        scene.add(tfCEP);
        scene.add(tfPizza);
        scene.add(tfObs);
    }
 
    public void clear() {
        scene.removeAll();
        scene.repaint();
        em.removeUserEventListener(this);
    }
 
    public void userEventReceived(UserEvent e) 
    {
        int type =e.getType();
        int code = e.getCode();
        if(type==HKeyEvent.KEY_PRESSED) {
            if (code== HRcEvent.VK_ENTER) {
                this.clear();
                TelaFinal tela = new TelaFinal(scene);
                tela.init();
            }
        }
    }
}

TelaFinal.java

import org.dvb.event.*;
import org.havi.ui.*;
import org.havi.ui.event.*;
public class TelaFinal implements UserEventListener {
    private HScene scene;
    private EventManager em;
    Imagens imagens;
    HIcon hi;
    public TelaFinal(HScene scene){
        this.scene=scene;
        em = EventManager.getInstance();
        imagens = new Imagens();
    }
    public void init() {
        hi = new HIcon(imagens.carregarImagem(Imagens.telaFinal),0,0,640,540);
        UserEventRepository uer = new UserEventRepository("TelaFinal");
        uer.addKey(HRcEvent.VK_ENTER);
        uer.addAllArrowKeys();
        em.addUserEventListener(this,uer);
 
        scene.add(hi);
        scene.repaint();
 
    }
 
    public void clear() {
        scene.removeAll();
        scene.repaint();
        em.removeUserEventListener(this);
    }
 
    public void userEventReceived(UserEvent e) 
    {
        int type =e.getType();
        int code = e.getCode();
 
        if(type==HKeyEvent.KEY_PRESSED) {
            if (code== HRcEvent.VK_ENTER) {
                this.clear();
            }
        }
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License