Sie sind auf Seite 1von 1

Cdigo ejemplo de uso de TextField, DateField, ChoiceGroup

import javax.microedition.midlet.*;
/**
* @author unica_000
*/
import javax.microedition.lcdui.*;
public class UI extends MIDlet implements CommandListener {
private final Command exitCommand;
private final Display display;
private final Form screen;
public UI() {
String[] estados = {"Casado","Soltero","Divorciado","Viudo"};
// Se obtiene el Display del midlet.
display = Display.getDisplay(this);
// Se crea el comando Salir.
exitCommand = new Command("Salir", Command.EXIT,2);
// Se crea la pantalla principal (un formulario)
screen = new Form("Interfaz de usuario");
// Se crea y se aade los elemento 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);
// Se aade el comando Salir y se indica que clase lo manejar
screen.addCommand(exitCommand);
screen.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
// Se selecciona 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();
}
}
}

Das könnte Ihnen auch gefallen