You are on page 1of 13

J2ME

Curso JEDI Gratuito Exige Registro

Mdulo 5 - Desenvolvimento de Aplicaes Mveis - http://jedi.wv.com.br/

Alguns PDF disponibilizei no SAPU (os vdeos no)

J2ME

CDC

Foundation Profile Personal Profile MIDP

CLDC

Lio 1, 2 e 3 do curso JEDI

Disponvel no SAPU

Desenvolvimento Orientado a Objetos III- TADS/UCPel - Prof. Luciano E. Mertins

CLDC e MIDP - Netbeans

Duas abordagens no Netbens

Atravs de wizards

Avaliado na aula passada Vantagem


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

Sem utilizar wizards

Vantagem

Completo controle do cdigo. Permite compor o sistema com diversas classes. Apresenta o fluxo entre telas e formulrios. No visual no desenvolvimento

Desvantagem

Apenas na execuo do emulador verifica-se o layout de tela.

Obs.: Conhecer ambas permite escolher com convico!


2

Desenvolvimento Orientado a Objetos III- TADS/UCPel - Prof. Luciano E. Mertins

Projeto J2ME - Netbeans

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

Sem Wizard!

Desmarcar!!!!

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

Ciclo de Vida Aplicao J2ME - CLDC/MIDP

Define como o dispositivo controla as suas aplicaes

package teste; import javax.microedition.midlet.MIDlet; public class AppPrincipal extends MIDlet { public void startApp() { } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

Interfaces MIDP

Interface de Auto Nvel

Favorece a construo de aplicaes e sistemas


Componentes prontos Ajustados a tela do aparelho de forma automtica Pouco controle visual

Interface de Baixo Nvel

Favorece a criao de jogos


Nenhum componente Tela fica a merce do desenvolvedor Controle praticamente total

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

Classe MIDlet

Toda aplicao J2ME precisa ter uma classe filha de MIDlet

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

Ponto de Entrada J2ME => MIDlet

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

Exemplo com Interfaces de Alto Nvel


O detalhamento das interfaces de alto nvel do J2ME esto no material JEDI no SAPU.
E resumos podem ser encontrados na Internet como em: http://sistemasucp.posterous.com/j2me-entendendo-melhor-os-componentes http://www.wirelessbrasil.org/wirelessbr/colaboradores/corbera_martins/j2me_02.html

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) { } }

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

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; } } } }

No esquea os imports!! No esquea de colocar a classe em um package!!

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

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); } } }

No esquea os imports!! No esquea de colocar a classe em um package!!

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

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); } }

No esquea os imports!! No esquea de colocar a classe em um package!!

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

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

Desenvolvimento Orientado a Objetos I - TADS/UCPel - Prof. Luciano E. Mertins

13

You might also like