2° parcial de programación movil

|

En la semana que paso el Profe Grajales nos puso un examen que no pude(pudimos) entregar durante una hora de tiempo. Mas o menos el examen hiba así:

Crear la primera pantalla, cuando se acomplete el llenado del Gauge mostrar el formulario



























El código lo hice así:



1 /**
2 * @(#)Examen2.java
3 *
4 * @author: Gabriel Mtz. Najera
5 * Examen parcial 2
6 * @version 1.00 2007/10/31
7 */
8
9 import javax.microedition.midlet.*;
10 import javax.microedition.lcdui.*;
11 import java.util.*;
12
13 public class Examen2 extends MIDlet implements CommandListener,ItemStateListener {
14 private Command CmdSalir,CmdAceptar;
15 private TextField TxtUser,TxtPass,TxtHora,TxtFecha;
16 private Gauge GgeDinamico;
17 private Form FrmPrincipal, FrmSecundario;
18 private StringItem StrValor;
19 private DateField DtFecha,DtHora;
20 private Display Pantalla;
21
22 public Examen2(){
23 FrmPrincipal = new Form("Examen 2 ");
24 GgeDinamico = new Gauge("Gauge dinamico",true,10,1);
25 StrValor = new StringItem( "Valor:"," "+ GgeDinamico.getValue() );
26 //Fecha
27 DtFecha = new DateField("Fecha:",1);
28 DtFecha.setDate(new Date() );
29 //hora
30 DtHora = new DateField("Hora:",2);
31 DtHora.setDate( new Date() );
32
33 FrmPrincipal.append(DtFecha);
34 FrmPrincipal.append(DtHora);
35 FrmPrincipal.append(GgeDinamico);
36 FrmPrincipal.append(StrValor);
37 //Como no hay comandos en FrmPrincipal,Se agrega el Listener de Gauge
38 FrmPrincipal.setItemStateListener(this);
39 }
40 public void AsignarSecundario(){
41 FrmSecundario = new Form("Formulario 2");
42 TxtFecha = new TextField("Fecha:",null,30,TextField.UNEDITABLE);
43 TxtFecha.setString(""+DtFecha.getDate() );
44 TxtHora = new TextField("Hora:",null,30,TextField.UNEDITABLE);
45 TxtHora.setString("" +DtHora.getDate() );
46
47 TxtUser = new TextField("Usuario:",null,30,TextField.ANY);
48 TxtPass = new TextField("Contraseña:",null,30,TextField.PASSWORD);
49 CmdSalir = new Command("Salir",Command.EXIT,1);
50 CmdAceptar = new Command("Aceptar",Command.OK,2);
51
52 FrmSecundario.append(TxtFecha);
53 FrmSecundario.append(TxtHora);
54 FrmSecundario.append(TxtUser);
55 FrmSecundario.append(TxtPass);
56
57 FrmSecundario.addCommand(CmdSalir);
58 FrmSecundario.addCommand(CmdAceptar);
59 //Se agrega el Listener al segundo formulario
60 FrmSecundario.setCommandListener(this);
61 }
62
63 public void startApp(){
64 Pantalla = Display.getDisplay(this);
65 Pantalla.setCurrent(FrmPrincipal);
66
67 }
68 public void pauseApp(){
69
70 }
71 public void destroyApp(boolean unconditional){
72 notifyDestroyed();
73 }
74 public void commandAction( Command cmd, Displayable dsp){
75 if(cmd==CmdSalir){
76 destroyApp(true);
77 }
78
79 }
80 public void itemStateChanged(Item itm){
81 if(itm==GgeDinamico){
82 StrValor.setText(""+GgeDinamico.getValue() );
83 if( GgeDinamico.getValue()==GgeDinamico.getMaxValue() ){
84 AsignarSecundario();
85 Pantalla.setCurrent(FrmSecundario);
86 }
87 }
88 }
89
90 }

perdón por no postear más seguido, por cierto ya tengo un año con el blog XD.

1 comentarios:

Gabo dijo...

El segundo formulario debería mostrar solamente en los respectivos TextField la hora en uno y la fecha en el otro. En este ejemplo no se hace así.

Para ello hay que usar la clase calendar del paquete java.util.*