Friday, April 8, 2011

Community Service Recommendation













Code


/
* * To change this template, choose Tools javax.microedition.midlet .*;
import javax.microedition.lcdui .*;
javax.microedition.rms import .*;

public class Client extends MIDlet implements CommandListener
{static final String DB = "data" Customer
c = new Customer ();

private Display display;
ChoiceGroup
private money;
ChoiceGroup private pesos private
Form frmAgregar; private TextField name; off private TextField; Form private frmEliminar;
cmdEliminar private Command; name2 private TextField; Form private frmBuscar;
cmdBuscar private Command;
name3 private TextField; private Form frmResultados;
itemResultados public int;
private
List elmenu;
cmdSalir private Command;
cmdSeleccionar private Command;
private
Alert
ADVISED; private Command
cmdRegresar;
public
Customers () {

//------------------------
/ / Prepare Display
/ / - -------------------
display = Display.getDisplay (this);


//---------------- -----------
/ / prepares Base Data

//----------------------- 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) ;}


//-------------------------
/ / Main Menu
//---------- ------------
String options [] = {"Add", "Delete", "Search", "About Image of
..."}; figures [] = 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 :","", 3 , TextField.NUMERIC);
frmAgregar.append (name);
frmAgregar.append (discount);
frmAgregar.addCommand (cmdGuardar)
frmAgregar.addCommand (cmdCancel)
frmAgregar.setCommandListener (this);
ChoiceGroup = new currency ("Currency Type" Choice.EXCLUSIVE)
currency. append ("USD", 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 ("Search", 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 ... //-----------------------

ADVISED = new Alert ("What's Up Men ???");
acercade.setTimeout (Alert.FOREVER)
credits String =" made by: \\ nIvan Muñoz Manrique "

if (pantalla.numColors ()> 2)

{String icon = (pantalla.isColor ())? "/ JavaPowered-8.png": "/ JavaPowered-2Png"

try {Image image = Image.createImage
(icon);
ADVISED. setImage (image);

} catch (java.io.IOException x) {}}

acercade.setString (credits);
acercade.addCommand (cmdRegresar)
acercade.setCommandListener(this);

}
public void startApp() throws MIDletStateChangeException {
pantalla.setCurrent(elmenu);

}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s){
switch(c.getCommandType())
{
case Command.ITEM:
switch(elmenu.getSelectedIndex())
{
case 0: //añadir
pantalla.setCurrent(frmAgregar);
break;
case 1: //eliminar
pantalla.setCurrent(frmEliminar);
break;
case 2: //busqueda
pantalla.setCurrent(frmBuscar);
break;
case 3: //acerca de...
pantalla.setCurrent(acercade);
break;

}
break;
case Command.EXIT:
destroyApp(false);
notifyDestroyed();
break;
case Command.BACK:
pantalla.setCurrent(elmenu);
limpiar();
break;
case Command.OK:
if (c == cmdGuardar)
{
this.c.nombre = nombre.getString();
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 * 12;
}
else if(moneda.isSelected(1))
{
elmenu.setTitle(moneda.getString(1));
this.c.moneda = moneda.getString (1);
this.c.pesos = this.c.descuento * 14;

} else if (moneda.isSelected (2)) {

elmenu.setTitle (currency . getString (2));
this.c.moneda = moneda.getString (2);
this.c.pesos = this.c.descuento * 16;}


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 ("");
}

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);
os.writeLong (discount);
os.writeLong (pesos )
os.writeUTF (currency);
os.flush ();

} catch (IOException ioe) {}

byte [] b = baos.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 {

= new ByteArrayInputStream ByteArrayInputStream Baís (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;}

/ / Find

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 ()) {

registros.nextRecordId index = ();

try {ByteArrayInputStream bais
= new ByteArrayInputStream (rs.getRecord (index));
DataInputStream is = new DataInputStream (bais);

try {
is.readUTF elnornbre = ();
is.readLong amount = ();
is.readLong pesos = ();
is.readUTF currency = ();

if (this.nombre.equals ("*") "+ 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;}




}} / / class Customer


0 comments:

Post a Comment