FORMATO: GUIA DE APRENDIZAJE PARA LA FORMACIN PROFESIONAL F08 9227 014 / 04 10 Versin 1 PROCESO: EJECUCIN DE LA FORMACIN PROFESIONAL PROCEDIMIENTO:
TO: GESTIN DE PROYECTOS FORMATIVOS
Modelo de Mejora Continua
EJEMPLO DE MANEJO DE REGISTROS RMS (ADICIONAR, ELIMINAR, VER Y ACTUALIZAR) UTILIZANDO EL RECORD STORE
package hello; import [Link].*; import [Link].*; import [Link]; import [Link]; import [Link]; import [Link]; import [Link].*; import [Link].*; import [Link]; import [Link]; import [Link]; import [Link];
public class rms1 extends MIDlet implements CommandListener{ private Display pantalla; private Form form; private TextField nombre; private TextField edad;
private Command guardar, salir, ver, borrar, actualizar; private RecordStore rs;
public rms1 () { pantalla = [Link](this); form = new Form("Almacenamiento"); nombre = new TextField("Nombre", "", 15, [Link]); edad = new TextField("Edad", "", 3, [Link]); salir = new Command("Salir", [Link], 0); guardar = new Command("Guardar", [Link], 1); ver = new Command("Ver", [Link], 2); borrar = new Command("Borrar", [Link], 3); actualizar = new Command("Actualizar", [Link], 4);
try { rs = [Link]("Listado", true); } catch (RecordStoreException ex) { [Link](); }
[Link](nombre); [Link](edad); [Link](guardar); [Link](salir); [Link](borrar); [Link](actualizar);
[Link](ver); [Link](this);
public void startApp() {
[Link](form);
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public void commandAction(Command c, Displayable dsplbl) {
if (c == salir){ destroyApp(false); notifyDestroyed(); }
if (c == guardar){
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Se construye un DataOutputStream para escribir el registro del Record Store DataOutputStream daos = new DataOutputStream(baos);
Date fecha = new Date();
[Link](new String([Link]())); [Link]([Link]()); [Link]([Link]([Link]())); [Link](new String("Prueba")); [Link](); // Se convierte el ByteArrayOutputStream (baos) a un arreglo de bytes byte[] bytes = [Link](); // se invoca addRecord () para agregar el registro al Record Store. [Link](bytes,0,[Link]);
} catch (IOException ex) { [Link](); } catch (RecordStoreException ex) { [Link](); } } if (c == ver){
try { byte[] bytes; for (int i = 1; i <= [Link](); i++) {
bytes = [Link](i); DataInputStream is = new DataInputStream(new ByteArrayInputStream(bytes)); [Link]("Los Registros son: "+[Link]()+" "+[Link]()+" "+[Link]()+" "+[Link]());
} } catch (Exception e) {
if (c == actualizar){
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream daos = new DataOutputStream(baos);
Date fecha = new Date();
[Link](new String([Link]()));
[Link]([Link]()); [Link]([Link]([Link]())); [Link](new String("prueba")); [Link](); byte[] bytes = [Link](); [Link](1, bytes, 0, [Link]);
} catch (IOException ex) { [Link](); } catch (RecordStoreException ex) { [Link](); }
if (c==borrar){ try {
Vector recordIDs = new Vector(); int lastID = 1; // Se agrega el ID del Vector [Link](new Integer(++lastID)); //Ahora, borramos un registro, encontramos el record ID del registro que queremos eliminar :
Enumeration IDs = [Link](); while([Link]()) { int id = ((Integer) [Link]()).intValue(); //Comparar para ver si esto es el registro que desea elimininar // Hacemos el llamado [Link](id); }
} catch (RecordStoreException ex) { [Link](); } }
} }
Nota: Implementar un StringItem para mostrar los registros en el MIDlet y descargar la aplicacin en el dispositivo mvil.