You are on page 1of 3

ISTP Manuel Seoane Corrales

Taller de Aplicaciones Mviles

GUIA DE PRCTICA N 2
El siguiente programa muestra el uso de varios elementos en un formulario a la vez, solicita el
ingreso de un nombre, permite seleccionar una fecha y permite seleccionar el estado civil.
En el mismo proyecto y paquete anterior. Digita el siguiente cdigo para el programa y ejecute,
tambin para la Nro. 04 y 05.
EJERCICIO 03:
package Ejercicios;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Eje_03 extends MIDlet implements CommandListener {
private Command exitCommand;
private Display display;
private Form screen;
public Eje_03() {
String[] estados = {"Casado","Soltero","Divorciado","Viudo"};
// Obtenemos el objeto Display del midlet.
display = Display.getDisplay(this);
// Creamos el comando Salir.
exitCommand = new Command("Salir", Command.EXIT,2);
// Creamos la pantalla principal (un formulario)
screen = new Form("Interfaz de usuario");
// Creamos y aadimos los elemento que vamos a utilizar
TextField nombre = new TextField("Nombre","",30,TextField.ANY);
DateField fecha_nac = new DateField("Fecha de nacimiento", DateField.DATE);
ChoiceGroup estado = new ChoiceGroup("Estado",List.EXCLUSIVE,estados,null);
screen.append(nombre);
screen.append(fecha_nac);
screen.append(estado);
// Aadimos el comando Salir e indicamos que clase lo manejar
screen.addCommand(exitCommand);
screen.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
// Seleccionamos la pantalla a mostrar
display.setCurrent(screen);
}
public void pauseApp() {
}
public void destroyApp(boolean incondicional) {
}
public void commandAction(Command c, Displayable s) {
// Salir
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}

Prof. Bernardo C. Hermitao Atencio

Pgina 1

ISTP Manuel Seoane Corrales

Taller de Aplicaciones Mviles

EJERCICIO 04:
Aplicacin donde se ingresa un centmetros y devuelve en pies o pulgadas (use ChoiceGroup)
package Ejercicios;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Eje_04 extends MIDlet implements CommandListener {
private Command salir,ok;private Display display;
private Form pantalla;private TextField t1;
private ChoiceGroup g1; private StringItem s1;
public Eje_04(){
display = Display.getDisplay(this);
pantalla = new Form("Zeka ");
salir = new Command("Salir", Command.EXIT, 1);
pantalla.addCommand(salir); pantalla.setCommandListener(this);
ok = new Command("Aceptar", Command.OK, 1);
pantalla.addCommand(ok);
pantalla.setCommandListener(this);
t1=new TextField("ingrese un nmero en centmetros :",null,10, TextField.ANY);
pantalla.append(t1);
String[] cambio={"Pies","Pulgadas"};
g1=new ChoiceGroup("Turno",List.EXCLUSIVE,cambio,null);
pantalla.append(g1);
s1=new StringItem("El valor comvertido es:",null);
pantalla.append(s1);
}
public void startApp() throws MIDletStateChangeException{
display.setCurrent(pantalla);
}
public void pauseApp(){ }
public void destroyApp (boolean incondicional){ }
public void commandAction(Command c, Displayable s){
if (c == salir){
destroyApp(true);
notifyDestroyed();
}else if(c==ok){
mostrar();
}
}
public void mostrar(){
int q=g1.getSelectedIndex();
double k=Double.parseDouble(t1.getString());
double z=0;
if (q==0){
z=k/30.48;
}
if (q==1){
z=k/2.54;
}
s1.setText(""+z);
}
}

Prof. Bernardo C. Hermitao Atencio

Pgina 2

ISTP Manuel Seoane Corrales

Taller de Aplicaciones Mviles

EJERCICIO 05:
Crear una aplicacin donde se ingrese Nombre, Curso (programacin, diseo, ensamblaje),
turno(maana, tarde, noche) y num. de inscripcin, devolver el cdigo generado por los dos
primeros caracteres de curso ms dos primeros caracteres de turno seguido de 00 y luego del
num. De inscripcin.
package Ejercicios;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Eje_05 extends MIDlet implements CommandListener {
private Command salir,ok;private Display display;
private Form pantalla;private TextField t1;
private ChoiceGroup g1;ChoiceGroup g2; private StringItem s1;
public Eje_05(){
display = Display.getDisplay(this);
pantalla = new Form("Uso de ChoiceGroup");
salir = new Command("Salir", Command.EXIT, 1);
pantalla.addCommand(salir); pantalla.setCommandListener(this);
ok = new Command("Aceptar", Command.OK, 1);
pantalla.addCommand(ok);
pantalla.setCommandListener(this);
t1=new TextField("Ingrese Nombre:",null,10, TextField.ANY);
pantalla.append(t1);
String[] turnos={"Maana", "Tarde", "Noche"};
g1=new ChoiceGroup("Turno",List.EXCLUSIVE,turnos,null);
pantalla.append(g1);
String[] curso={"Programacin", "Diseo", "Ensamblajee"};
g2=new ChoiceGroup("curso",List.EXCLUSIVE,curso,null);
pantalla.append(g2);
s1=new StringItem("Turno seleccionado:",null);
pantalla.append(s1);
}
public void startApp() throws MIDletStateChangeException{
display.setCurrent(pantalla);
}
public void pauseApp(){ }
public void destroyApp (boolean incondicional){ }
public void commandAction(Command c, Displayable s){
if (c == salir){
destroyApp(true);
notifyDestroyed();
}else if(c==ok){
mostrar();
}
}
public void mostrar(){
int q=g1.getSelectedIndex();
int r=g2.getSelectedIndex();
String s="Hola "+ t1.getString()+" Ud. ha seleccionado el turno: "+g1.getString(q)+" y el curso:
"+g2.getString(r);
s1.setText(s);
}
}

Prof. Bernardo C. Hermitao Atencio

Pgina 3

You might also like