Professional Documents
Culture Documents
J2ME
CDC
CLDC
Disponvel no SAPU
Atravs de wizards
Visual e intuitivo Apresenta o fluxo entre telas e formulrios No favorece o domnio do que esta sendo construdo. Sistemas maiores produziro um nico arquivo .java muito grande. Integrao com componentes de terceiros mais complexa.
Desvantagem
Vantagem
Completo controle do cdigo. Permite compor o sistema com diversas classes. Apresenta o fluxo entre telas e formulrios. No visual no desenvolvimento
Desvantagem
Sem Wizard!
Desmarcar!!!!
package teste; import javax.microedition.midlet.MIDlet; public class AppPrincipal extends MIDlet { public void startApp() { } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }
Interfaces MIDP
Componentes prontos Ajustados a tela do aparelho de forma automtica Pouco controle visual
Classe MIDlet
Nos prximos slides apresentado uma pequena aplicao que pode servir de modelo para a construo de aplicaes mais complexas. Para criar o MIDLet abaixo como Ponto de Entrada use o slide 6
package tads.aula2; import javax.microedition.lcdui.Display; import javax.microedition.midlet.*; /** * @author mertins */ public class MIDPrincipal extends MIDlet { public void startApp() { Display display = Display.getDisplay(this); FrmInicial frmPrincipal = new FrmInicial("Tela inicial", this); display.setCurrent(frmPrincipal); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }
Tela Inicial
public class FrmInicial extends Form implements CommandListener { private MIDPrincipal mid; private Command opcSair; private Command opcEscolher; private ChoiceGroup cgrupoOpcao; public FrmInicial(String title, MIDPrincipal mid) { super(title); this.mid = mid; this.opcSair = new Command("Sair", Command.EXIT, 0); this.addCommand(opcSair); this.opcEscolher = new Command("Escolha", Command.ITEM, 1); this.addCommand(opcSair); this.addCommand(opcEscolher); this.setCommandListener(this); this.cgrupoOpcao = new ChoiceGroup("Escolha a opo", Choice.EXCLUSIVE); this.cgrupoOpcao.append("Texto 1", null); this.cgrupoOpcao.append("Lista 2", null); append(this.cgrupoOpcao); } public void commandAction(Command c, Displayable d) { if (c == opcSair) { mid.destroyApp(true); mid.notifyDestroyed(); } else if (c == opcEscolher) { Display display = Display.getDisplay(mid); switch (this.cgrupoOpcao.getSelectedIndex()) { case 0: display.setCurrent(new TxtBoxTexto("Texto Livre", this, mid)); break; case 1: display.setCurrent(new LstLista("Listagem", this, mid)); break; } } } }
10
TextBox
/** * * @author mertins */ public class TxtBoxTexto extends TextBox implements CommandListener { private MIDlet mid; private Command opcVoltar; private Command opcMostrar; private Displayable frmVoltar; public TxtBoxTexto(String title, Displayable frmVoltar, MIDlet mid) { super(title, "frase inicial", 400, TextField.ANY); this.mid = mid; this.frmVoltar = frmVoltar; this.opcVoltar = new Command("Voltar", Command.EXIT, 0); this.opcMostrar = new Command("Mostrar", Command.ITEM, 1); this.addCommand(opcVoltar); this.addCommand(opcMostrar); this.setCommandListener(this); } public void commandAction(Command c, Displayable d) { Display display = Display.getDisplay(mid); if (c == opcVoltar) { display.setCurrent(frmVoltar); } else if (c == opcMostrar) { Alert alert = new Alert("Informao"); alert.setString("Apresentando: "+this.getString()); display.setCurrent(alert); } } }
11
List
public class LstLista extends List implements CommandListener { private MIDlet mid; private Command opcVoltar; private Command opcMostrar; private Displayable frmVoltar; private String[] lst = {"Elemento 1", "Elemento 2", "Elemento 3", "Elemento 4"}; public LstLista(String title, Displayable frmVoltar, MIDlet mid) { super(title, List.MULTIPLE); this.mid = mid; this.frmVoltar = frmVoltar; this.opcVoltar = new Command("Voltar", Command.EXIT, 0); this.opcMostrar = new Command("Mostrar", Command.ITEM, 1); this.addCommand(opcVoltar); this.addCommand(opcMostrar); this.setCommandListener(this); for (int i = 0; i < lst.length; i++) { append(lst[i], null); } } public void commandAction(Command c, Displayable d) { Display display = Display.getDisplay(mid); if (c == opcVoltar) { display.setCurrent(frmVoltar); } else if (c == opcMostrar) { Alert alert = new Alert("Informao"); StringBuffer sb = new StringBuffer("Apresentando: "); boolean[] retornos = new boolean[this.size()]; this.getSelectedFlags(retornos); for (int i = 0; i < retornos.length; i++) { if (retornos[i]) { sb.append(this.getString(i)); sb.append(" # "); } } alert.setString(sb.toString()); display.setCurrent(alert); } }
12
Exerccios
1. Implemente o cdigo dos slides acima 2. Estude e implemente os cdigos no material do JEDI, disponibilizado no SAPU 3. Faa um aplicativo para armazenar informaes referentes ao abastecimento do veiculo e que permita controlar o consumo do mesmo (armazene em um vetor). Devem ser coletadas informaes do tipo: Quilometragem do veiculo Litros abastecidos Valor do abastecimento Data do abastecimento Nome do posto
13