Vous êtes sur la page 1sur 8

APLICACIONES MOBILES

Practica #4
import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.AlertType; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.List; import javax.microedition.midlet.MIDlet;

public class Ejemplo4 extends MIDlet implements CommandListener {

//crear un Display cuyo nombre es display private Display display; //crear una boton de Comando cuyo nombre es salir private Command salir = new Command("Salir", Command.EXIT, 1); //crear una boton de Comando cuyo nombre es enviar private Command enviar = new Command("Enviar", Command.SCREEN, 2); //crear una lista cuyo nombre es list private List list = new List("Selecciona Opcion", List.MULTIPLE);

public Ejemplo4() { //obtener la pantalla actual display = Display.getDisplay(this); //crear la lista de seleccion multiple list.append("Libros", null); list.append("Peliculas", null); list.append("Television", null); list.append("Radio", null); //aadir los botonoes a la lista list.addCommand(salir);

APLICACIONES MOBILES
list.addCommand(enviar); list.setCommandListener(this); } //Metodo que se ejecuta al iniciar la aplicacion public void startApp() { //mostrar la lista en la pantalla actual display.setCurrent(list); }

public void pauseApp() { }

public void destroyApp(boolean unconditional) { }

public void commandAction(Command command, Displayable Displayable) { //seleccione el boton enviar if (command == enviar) { //crear un arreglo tipo boolean en igual catidad de elementos de la lista boolean selecciones[] = new boolean[list.size()]; //Deben utilizarse cuando debemos hacer muchas modificaciones en un String StringBuffer mensaje = new StringBuffer(); /*indicamos en el arreglo colocando el valor true segun el elememento seleccionado de la lista*/ list.getSelectedFlags(selecciones); //recorremos el arreglo selecciones for (int i = 0; i < selecciones.length; i++) { //preguntamos segun el arreglo cual fue el elememento seleccionado if (selecciones[i]) { /*si esta seleccionado , asigname el texto de elementos de la lista a la cadena mensaje */

APLICACIONES MOBILES
mensaje.append(list.getString(i)); mensaje.append(" "); } } //mostramos uan alerta indicando que elemento fue seleccionado Alert alert = new Alert("Seleccionado", mensaje.toString(), null, null); //mensjae si limite de tiempo de ser mostrado alert.setTimeout(Alert.FOREVER); //mensaje tipo informacion alert.setType(AlertType.INFO); display.setCurrent(alert); //list.removeCommand(enviar); } //presione el command salir else if (command == salir) { destroyApp(false); notifyDestroyed(); } } }

APLICACIONES MOBILES

APLICACIONES MOBILES

Practica #5
import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.AlertType; import javax.microedition.lcdui.ChoiceGroup; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.DateField; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Gauge; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.ItemCommandListener; import javax.microedition.lcdui.ItemStateListener; import javax.microedition.lcdui.StringItem; import javax.microedition.lcdui.TextField; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException;

public class Ejemplo5 extends MIDlet implements CommandListener,ItemCommandListener { // Referencia a la pantalla private Display pantalla = Display.getDisplay(this);

// Creacin de formularios y sus controles private Form frmProveedor = new Form("Registro de Proveedor"); // razon social private TextField txtRazon = new TextField("Razon Social", "", 40, TextField.ANY); // direccion Proveedor private TextField txtDireccion = new TextField("Direccion", "", 40, TextField.ANY);

APLICACIONES MOBILES
// tipo Proveedor private String tipo[] = {"Natural", "Juridica"};

private ChoiceGroup chgTipo = new ChoiceGroup("Tipo", ChoiceGroup.EXCLUSIVE, tipo, null); private TextField txfDocumento = new TextField("Documento", "", 11, TextField.NUMERIC); private DateField dFechaInicio = new DateField("Fecha Inicio Operaciones", DateField.DATE); private Gauge gauDcto = new Gauge("Descuento:", true, 50, 0); private StringItem sGrabar = new StringItem("", "Grabar", StringItem.BUTTON); //command salir private Command cmdExit = new Command("Salir", Command.EXIT, 2); //command grabar private Command cmdSave = new Command("Grabar", Command.ITEM, 2); //command nuevo private Command cmdNew = new Command("Nuevo ", Command.ITEM, 2);

public Ejemplo5() {

// Agregar los controles al formulario (frmProveedor) frmProveedor.append(txtRazon); frmProveedor.append(txtDireccion); frmProveedor.append(chgTipo); frmProveedor.append(txfDocumento); frmProveedor.append(dFechaInicio); frmProveedor.append(gauDcto); frmProveedor.append(sGrabar);

// Agregar command al formulario frmProveedor.addCommand(cmdExit); frmProveedor.setCommandListener(this);

APLICACIONES MOBILES

// Agregar command del control sGrabar sGrabar.addCommand(cmdSave); sGrabar.setItemCommandListener(this); sGrabar.setDefaultCommand(cmdSave); }

protected void destroyApp(boolean arg0) { }

protected void pauseApp() { }

protected void startApp() throws MIDletStateChangeException { pantalla.setCurrent(frmProveedor); }

public void commandAction(Command c, Displayable d) {

//seleccionar salir if(c == cmdExit) { destroyApp(false); notifyDestroyed(); } }

public void commandAction(Command c, Item i) { // seleccionar grabar if(c == cmdSave) {

APLICACIONES MOBILES
// Concatenar datos String strMensaje = "Proveedor" + "\n\rRazon Social: " + txtRazon.getString() + "\n\rTipo: " + chgTipo.getString(chgTipo.getSelectedIndex()) + "\n\rDocumento: " + txfDocumento.getString();

// Muestra un Alert con los datos Alert alerta1 = new Alert("Proveedor registrado", strMensaje, null, AlertType.INFO); pantalla.setCurrent(alerta1); } else if(c == cmdNew) { // Si se pulso el boton Nuevo Alert alerta2 = new Alert("Mensaje", "En construccion", null, AlertType.INFO); pantalla.setCurrent(alerta2); } } }

Vous aimerez peut-être aussi