Version 2.0 mobile application
/*
* To change this template, choose Tools Tmoneda String = "Dollar" private
cmdVer Command;
TextBox t = null;
Customer c = new Customer ();
ChoiceGroup
private money;
ChoiceGroup private pesos
txtPesos public TextField;
private Display display;
Form private
frmAgregar;
cmdGuardar private Command;
cmdCancel private Command;
private TextField name;
off private TextField;
private
Form frmEliminar;
cmdEliminar private Command;
name2 private TextField;
private
Form frmBuscar;
private Command cmdBuscar;
private TextField name3;
private
Form frmResultados;
itemResultados public int;
private
List elmenu;
cmdSalir private Command;
cmdSeleccionar private Command;
private
Form frmConeccion;
cmdRegresar private Command;
txtcantidadmoneda private TextField;
V2Monedas public
() {
//.........................
/ / Prepare Display
//.........................
display = Display.getDisplay (this);
//.........................
/ / Prepare //.........................
Database
RecordStore rs = null;
try
{
RecordStore.deleteRecordStore(BD);
}
catch( Exception e ){}
try
{
rs = RecordStore.openRecordStore(BD, true);
rs.closeRecordStore();
}
catch( RecordStoreException e )
{
System.out.println( e );
}
/*
* ----------------------
* menu principal
* ----------------------
*/
String opciones[] = {"Añadir", "Eliminar", "Busqueda", "Cambio."};
Image figuras[] = new Image[4];
try
figures
{[0] = Image.createImage ("/ nuevo.png");
figures [1] = Image.createImage ("/ borrar.png");
figures [2] = Image.createImage ("/ buscar.png ");
figures [3] = Image.createImage (" / acercade.png ");
} catch (Exception e) {}
cmdSeleccionar = new Command (" Select ", Command.ITEM, 1) ;
cmdSalir = new Command ("Exit", Command.EXIT, 1);
elmenu = new List ("Mobile System", Choice.IMPLICIT, options, shapes);
elmenu.setSelectCommand (cmdSeleccionar) elmenu.addCommand
(cmdSalir)
elmenu.setCommandListener (this);
//-----------------------
/ / Add
//-------- ---------------
cmdGuardar = new Command ("Save", Command.OK, 2);
cmdCancel = new Command ("Cancel" Command.BACK, 2);
frmAgregar = new Form ("Add Customer");
name = new TextField ("Name :","", 30, TextField.ANY)
discount = new TextField (" Number :","", 4, TextField. NUMERIC);
frmAgregar.append (name);
frmAgregar.append (discount);
frmAgregar.addCommand (cmdGuardar)
frmAgregar.addCommand (cmdCancel)
frmAgregar.setCommandListener (this);
ChoiceGroup
= new currency ("Currency Type" Choice.EXCLUSIVE)
moneda.append ("Dolores", null);
moneda.append ( Euros ", null);
moneda.append (" Yen ", null);
frmAgregar.append (currency);
//-------------------
/ / Remove
//-------------------
cmdEliminar = new Command ("Delete", Command.OK, 2);
frmEliminar = new Form (" Delete Customer ");
name2 = new TextField (" Name :","", 20, TextField.ANY)
frmEliminar.append (name2);
frmEliminar.addCommand (cmdEliminar)
frmEliminar.addCommand (cmdCancel)
frmEliminar.setCommandListener (this);
//--------------
---------
/ / Find
//-----------------------
cmdBuscar = new Command ("Find" Command . OK, 2);
frmBuscar = new Form ("Find Customer");
name3 = new TextField ("Name :","", 20, TextField.ANY)
frmBuscar.append (name3);
frmBuscar. AddCommand (cmdBuscar)
frmBuscar.addCommand (cmdCancel)
frmBuscar.setCommandListener (this);
//----------------------
/ / Search Results
//--------------- -------
cmdRegresar = new Command ("OK", Command.BACK, 1);
frmResultados = new Form ("Results");
frmResultados.append itemResultados = ("Results");
frmResultados. AddCommand (cmdRegresar)
frmResultados.setCommandListener (this);
//----------------------
/ / About De .. //----------------------
cmdVer = new Command ("View", Command.OK, 2);
frmConeccion = new Form (" Connect With Dollars ");
txtcantidadmoneda = new TextField("Dolares:","",10,TextField.ANY);
pesos = new ChoiceGroup("Tipo Moneda", Choice.EXCLUSIVE);
pesos.append("Dolares", null);
pesos.append("Euros", null);
pesos.append("Yens", null);
frmConeccion.addCommand(cmdVer);
frmConeccion.append(pesos);
frmConeccion.append(txtcantidadmoneda);
frmConeccion.addCommand(cmdCancelar);
frmConeccion.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
pantalla.setCurrent (elmenu) //////
} public void download (String url) throws IOException {
txtPesos = new TextField ("Name", "Ivan Manrique, 10, TextField.ANY)
StringBuffer b = new StringBuffer ();
InputStream is = null;
HttpConnection c = null;
String prompt = "";
try {long len = 0;
int ch = 0;
c = ( HttpConnection) Connector.open (url);
c.openInputStream is = ();
while ((ch = is.read ())! =- 1) {
b.append((char)ch);
}
txtcantidadmoneda.setString( b.toString().substring(0, 6));
} finally {
if(is !=null)
is.close();
if(c !=null)
c.close();
}
//pantalla.setCurrent(t);
}
//////
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s){
if(c == cmdVer)
{if (pesos.isSelected (0)) {
frmConeccion.setTitle ("Connected to Dollars");
url = "http://ivanchi.site88.net/php/cambio.php "
try {
download (url);
} catch (IOException e) {
System.out.println (" IOException "+ e);}
} else if (pesos.isSelected (1) )
{
pantalla.setCurrent (frmConeccion)
frmConeccion.setTitle ("Connected to Euros");
url = "http://ivanchi.site88.net/php/cambio.php?rmoneda=euro" try {
download (url);
} catch (IOException e) {
System.out.println ("IOException" + e);}
} else if (pesos.isSelected (2)) {
frmConeccion. setTitle ("Connected with Yens ");
url =" http://ivanchi.site88.net/php/cambio.php?rmoneda=yen "
try {
download (url);
} catch (IOException e) {
System.out.println ("IOException" + e);}
}}
switch (c.getCommandType ()) {
homes Command.ITEM:
switch (elmenu.getSelectedIndex ()) {
case 0: / / añadir
pantalla.setCurrent (frmAgregar)
break;
case 1: / / Delete
pantalla.setCurrent (frmEliminar)
break;
case 2: / / Find
pantalla.setCurrent (frmBuscar)
break;
case 3: / / About De ..
pantalla.setCurrent (frmConeccion)
display = Display.getDisplay (this);
try {
download (url);
} catch (IOException e)
{System.out.println ("IOException" + e);}
break;
} break;
case Command.EXIT:
destroyApp (false);
notifyDestroyed ();
break;
case Command . BACK:
pantalla.setCurrent (elmenu)
clean ();
break;
case Command.OK:
if (c == cmdGuardar) {
nombre.getString this.c.nombre = ();
this.c.descuento = Long.parseLong(descuento.getString());
this.c.moneda = "Vacio";
if(moneda.isSelected(0))
{
elmenu.setTitle(moneda.getString(0));
this.c.moneda = moneda.getString(0);
this.c.pesos = this.c.descuento*13;
}
else if(moneda.isSelected(1))
{
elmenu.setTitle(moneda.getString(1));
this.c.moneda = moneda.getString(1);
this.c.pesos = this.c.descuento * 18;
} else if (moneda.isSelected (2)) {
elmenu.setTitle (moneda.getString (2));
this.c.moneda = currency . getString (2);
this.c.pesos = this.c.descuento * 2;}
this.c.agregar ();
clean ();
pantalla.setCurrent (elmenu)
} else
if (c == cmdEliminar) {
nombre2.getString this.c.nombre = ();
frmResultados.delete (itemResultados)
itemResultados = frmResultados.append (this.c.eliminar ());
clean ();
pantalla.setCurrent (frmResultados)
} else if (c == cmdBuscar) {
nombre3.getString this.c.nombre = ();
frmResultados.delete (itemResultados)
itemResultados = frmResultados.append (this.c.buscar ());
clean ();
pantalla.setCurrent (frmResultados)
} break;}
} void clear () {
nombre.setString
("");
nombre2.setString ("");
nombre3.setString ("");
descuento.setString ("");
/ / txtcantidadmoneda.setString ("");}
class Customer {public String key
;
public String name;
private long off;
private long pesos;
private String currency;
/ / Add
public void add () {
RecordStore rs = null;
try {rs = RecordStore.openRecordStore
(BD, false); RecordEnumeration
records = rs.enumerateRecords (null, null, false);
baths = new ByteArrayOutputStream ByteArrayOutputStream ();
DataOutputStream os = new DataOutputStream (beams);
try {
os.writeUTF (name) you
. writeLong (discount);
os.writeLong (pesos);
os.writeUTF (currency);
os.flush ();
} catch (IOException ioe) {}
byte [] b = beams . toByteArray ();
try {
rs.addRecord (b, 0, b.length);
} catch (RecordStoreException rse) {}
rs.closeRecordStore ();
} catch (RecordStoreException e) {}}
/ / Remove
public String delete ()
{int index;
RecordStore rs = null;
String text = " No record found ";
try {rs = RecordStore.openRecordStore
(BD, false);
RecordEnumeration records = rs.enumerateRecords (null, null, false);
while (registros.hasNextElement ())
{
registros.nextRecordId index = ();
try {ByteArrayInputStream
Baís = new ByteArrayInputStream (rs.getRecord (index));
DataInputStream is = new DataInputStream (Baís);
try {key =
is.readUTF ( );
} catch (EOFException eofe)
{} catch (IOException ioe) {}
if (clave.equals (this.nombre)) {
try {
rs.deleteRecord (index);
text = "Record" + index + "deleted";
} catch (InvalidRecordIDException e) {}}
} catch (RecordStoreException e) {}}
rs.closeRecordStore ();
} catch (RecordStoreException e) {}
return text;}
/ / Search
public String find ()
{String text = "" String
elnornbre;
String currency;
long amount;
long pesos
eureka boolean = false;
RecordStore rs = null;
int index;
try {rs = RecordStore.openRecordStore (BD, false);
RecordEnumeration records = rs.enumerateRecords (null, null, false);
while (registros.hasNextElement ()) Index = {
registros.nextRecordId ();
try {ByteArrayInputStream bais
= new ByteArrayInputStream (rs.getRecord (index));
DataInputStream is = new DataInputStream (bais);
try {
elnornbre = is.readUTF ();
is.readLong amount = ();
is.readLong pesos = ();
is.readUTF currency = ();
if (this.nombre.equals ("*") "\\ NCustomers:" + elnornbre + "\\ nCantidad:" + amount + "\\ nMoneda:" + currency + "\\ NPES:" + weight + "\\ n \\ n";
eureka = true;
}
}
}
catch (EOFException eofe)
{} catch (IOException ice) {}
bais.reset ();
} catch (RecordStoreException e) {}}
rs.closeRecordStore ();}
catch (RecordStoreException e) {}
if (! Eureka)
text = "No se el meeting record";
return text;}
}} / / clase Customer
0 comments:
Post a Comment