J2ME Address Code

xiaoxiao2021-03-06  64

Tr>

Body {background: #fff; color: # 000; padding: 15px;

PRE {Border: None; Background: Transparent; Color: # 000;

.coloredcode .cmt {color: # 008000;

.coloredcode .cmtg {color: # 666;}

.coloredcode .st {color: # f00;}

.coloredcode .kwdt {color: # 666;}

.coloredcode. kwd {color: # 00f;}

.coloredcode .attr {color: # f00;}

.coloredcode .attrv {color: # 00f;}

.coloredcode .ec {color: # 00f;}

.coloredcode .tag {color: # 800000;

.coloredcode .dir {color: # 000; background: # feff22;

.coloredcode .sel {color: # 800000;

.coloredcode .val {color: # 00f;}

.coloredcode .unit {color: # 800000;

.coloredcode .sqlcmt {color: # 008080;

.coloredcode .sqlkwd {color: # 00f;}

.coloredcode .sqlkwd2 {color: # f0f;}

.coloredcode .sqlkwd3 {color: # 999;}

.coloredcode .sqlkwd4 {color: # 800000;

.coloredcode .num {color: # 00f;}

.coloredcode .sqlst {color: # 008000;

It took two days to get the address book, the basic function can be realized

Now I will give you to everyone. I hope everyone can find Bug.

Screenshot below

The following is the code: please keep the author copyright, thank you

/ / =====================MessageMIDlet main class ======================== =======

Package messagemidlet;

// Main class

Import javax.microedition.midlet. *;

Import javax.microedition.lcdui. *;

Public class messagemidlet extends MIDlet {

Public Static Messagemidlet MessagemIdlet;

PRIVATE MENUMIDLET MENUMIDLET = New MenumIdlet ();

/ ** constructor * /

Public messagemidlet () {

Messagemidlet = THIS;

}

/ ** main method * /

Public void startapp () {

Display.getdisplay (this) .Setcurrent (MenumIdlet);

}

/ ** Handle Pausing The Midlet * / Public Void PauseApp () {

}

/ ** Handle Destroying the MIDlet * /

Public void destroyApp (boolean unconditional) {

}

/ ** quit the midlet * /

Public static void quitApp () {

Messagemidlet.destroyApp (TRUE);

Messagemidlet.notifyDestroyed ();

Messagemidlet = NULL;

}

}

/ / ========================= ========================= ==========

/ / ========================= setGET Operation with the attribute used to the attribute ================================================================================================================================================= ================

Package messagemidlet;

/// java Why not set the properties like a C #, so trouble, I still like C #

PUBLIC CLASS setGet {

Public static int ID = 0;

Public static int delid = 0;

Public static intormid = 0;

Public static string str = NULL;

Public static boolean isok = true;

/ ** constructor * /

Public setget () {

}

Public static void setid (int id) {

ID = ID;

}

Public static int getId () {

Return ID;

}

Public static void setDelid (int id) {

Delid = ID;

}

Public static int getDelid () {

Return Delid;

}

Public static void setmodidId (int id) {

MODID = ID;

}

Public static int getModid () {

Return Modid;

}

Public static void setstr (String Str) {

Str = STR;

}

Public static string getStr () {

Return Str;

}

Public static void setistrue (boolean istrue) {

Isok = istrue;

}

Public static boolean getistrue () {

Return Isok;

}

}

/ / ========================= ========================= ==========

/ / ========================= pubclass public class (integrated some common attributes and methods for easy call) ========= =====================================================================================================================================================

Package messagemidlet;

Import javax.microedition.lcdui. *;

Import javax.microedition.rms. *;

Import java.io. *;

Public class pubclass {

Public Static Pubclass Pubclass;

Public Display Display; // Stage object

Public command exitCommand; // Leave the button object

Public Command SelectCommand; // Select button object

Public Command MenuCommand; // Main Directory

Public Command Okcommand;

Public Command Opercommand;

Public string [] menulist = {'address book,' About the author '}; // Main menu option

Public string [] mainlist = {'browsing contacts',' find contacts', add contact ',' other '};

Public String [] OperateList = {'editing contact', 'deleting contacts', all delete'}; //

// Simply modify the PersonPro property, other automatic generation, construct

Public String [] PersonPro = {'Name', 'Mobile', 'Email', 'Address', 'Other'}; // User Attributes

Public int layth = personPro.length; // User attribute

Public String DataName = 'Messages'; // Database Name

Public Boolean EXISTINGNOT = EXITINAME

RecordStore RS = NULL;

Public textfield [] Person = New TextField [Length];

Public stringItem [] Persondetail = new stringItem [length];

/** Constructor */

Public Pubclass () {for (int i = 0; i

New TextField (PersonPro [i],

'', 256, Textfield.Any;

Persondetail [i] =

New StringItem (PersonPro [i],

');

}

}

// acquirted the main directory list

Public string get_menulist (

INT i) {

IF

this.mainList.Length <0) {

Return

'';

}

Return

this.menulist [i];

}

// obtain a list of communication records

Public string get_mainlist (

Int j) {

IF

this.mainList.Length <0) {

Return

'';

}

Return

THIS.MAINLIST [J];

}

// Get a contact list

Public string get_operatelist (

Int j) {

IF

this.operateList.Length <0) {

Return

'';

}

Return

THIS.OPERATELIST [J];

}

/ / Return about

public

Void Return_Aboutmidlet () {

AboutMIDlet aboutmidlet =

New AboutMIDlet ();

Display.getdisplay (MessageMidlet.Messagemidlet) .SetCurrent (AboutMIDlet);

}

/ / Return to the main directory

public

Void return_mainmidlet () {

Mainmidlet mainmidlet =

NEW mainmidlet ();

Display.getdisplay (MessageMidlet.Messagemidlet) .SetCurrent (MainmIdlet);

}

/ / Return to the address list

public

Void Return_MenumIdlet () {

MenumIdlet menumidlet =

New menumidlet ();

Display.getdisplay (MessageMidlet.Messagemidlet) .SetCurrent (MenumIdlet);

}

// Return to the contact list

public

Void Return_PersonListMIDlet () {

PersonListMidlet PersonListMIdlet =

New personListMidlet ();

Display.getdisplay (MessageMidlet.Messagemidlet) .SetCurrent (PersonListMIDlet);

}

// Back to find contact

public

Void return_searchpersonmidlet () {

}

// Back to add a contact

public

Void Return_AddPersonmIdlet () {

AddPersonMidlet AddPersonMidlet =

New addpersonmidlet ();

Display.getdisplay (Messagemidlet.Messagemidlet) .SetCurrent (AddPersonMidlet);

}

// Return to operation

public

void return_operate device () {

OperateMIDlet OperateMIDlet =

New OperatemIdlet ();

Display.getdisplay (MessageMidlet.Messagemidlet) .SetCurrent (OperateMIDlet);

}

// Back to find

public

void return_searchmidlet () {

SearchMidlet searrchmidlet =

New searchmidlet ();

Display.getdisplay (MessageMidlet.Messagemidlet) .SetCurrent (Searrchmidlet);

}

/ / Back to find results

public

void return_searchoutmidlet () {

SearchOutmidlet searrchoutmidlet =

New searchOutmidlet ();

Display.getdisplay (MessageMidlet.Messagemidlet) .SetCurrent (SearrchoutMidlet);

}

// Return to edit

public

Void Return_ModifyPersonmidlet () {

ModifyPersonMidlet ModiftPersonMidlet =

New modifyPersonMidlet ();

Display.getdisplay (MessageMidlet.Messagemidlet) .SetCurrent (ModiftPersonmidlet);

}

/ / Return to the contact details and pass it into the corresponding ID value modify

public

Void return_persondetailmidlet () {

Persondetailmidlet PersondetAilmidlet =

New personDetailmidlet ();

Display.getdisplay (Messagemidlet.Messagemidlet) .SetCurrent (PERSONDETAILMIDLET);

}

// Warning window

public

Void Alert (String alertstring) {

Alert alert =

New alert

'Tips', Alertstring, CreateImage

'/images/1.png') ,alerttype.error);

Alert.SetTimeout (2000);

Display.getdisplay (MessageMidlet.Messagemidlet) .SetCurrent (Alert);

}

// Warning window, return to MainmIdlet after prompt

public

Void Alert (String alertstring, mainmidlet mainmidlet) {

Alert alert =

New alert

'Tips', Alertstring, CreateImage

'/images/1.png') ,alerttype.error);

Alert.SetTimeout (2000);

Display.getdisplay (Messagemidlet.Messagemidlet) .Setcurrent (Alert, MainmIdlet);

}

// Warning window, return to PersonListMIDlet after prompt

public

Void Alert (string alertstring, personlistmidlet personListmidlet) {

Alert alert =

New alert

'Tips', Alertstring, CreateImage

'/images/1.png') ,alerttype.error);

Alert.SetTimeout (2000);

Display.getdisplay (Messagemidlet.Messagemidlet) .SetCurrent (Alert, PersonListMIDlet);

}

// Create an image

public

Static Image CreateImage (String Name) {Image AIMAGE =

NULL;

Try {

AIMAGE = image.createImage (name);

}

Catch (IOException E) {

}

Return AIMAGE;

}

/ / Determine if the database exists, open, willbe the RecordStore object

Public RecordStore open () {

Boolean EXISTINOT =

False;

Boolean ok =

True;

EXInshipornot =

this.existing (dataname);

IF (existingornot) {

Try {

RS = RecordStore.OpenRecordStore (Dataname,

FALSE);

}

Catch (Exception E) {

OK =

False;

}

}

Else {

Try {

RS = RecordStore.OpenRecordStore (Dataname,

True);

OK =

True;

}

Catch (Exception E) {

OK =

False;

}

}

Return RS;

}

// Judgment character size

Public Boolean EXISTING (String RecordStoreString) {

Boolean EXISTINOT =

False;

RecordStore RS =

NULL;

IF (RecordStoreString.Length ()> 32)

Return

False;

Try {

RS = RecordStore.OpenRecordStore (RecordStoreString,

FALSE);

}

Catch (RecordStorenotFoundException E) {

EXInshipornot =

False;

}

Catch (Exception E) {

}

Finally {

Try {

Rs.closecordstore ();

}

Catch (Exception E) {

}

}

Return EXISTINGNOT;

}

}

/ / ========================= ========================= ==========

/ / ========================= Personclass user attribute class =================== =============

Package messagemidlet;

// Contact property class

Import java.io. *;

Import javax.microedition.rms. *; public

Class Personclass {

Private

Static Personclass Personclass;

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

public

Static

INT ID = -1;

/ / Set the static ID, do not need to be rebound after assignment without call

/ / Contact properties, arrays

Public String [] PersonPro =

NEW STRING [Pubclass.Length];

public

Void Write (String [] PersonPro) {

FOR

INT i = 0; I

This.PersonPro [i] = personpro [i];

}

}

// Set the ID, modify, delete, display

public

Void setRecordid (

INT ID) {

THIS.ID = ID;

}

// get the ID

public

Static

INT getRecordId () {

Return ID;

}

// Convert to byte

public

Byte [] changetobytearay () {

Byte [] DATA =

NULL;

Try {

ByteArrayoutputStream baos =

New byteArrayoutputStream ();

DataOutputStream DOS =

New DataOutputStream (baos);

FOR

INT J = 0; J <

THIS.PERSONPRO.LENGTH; J ) {

Dos.writeutf

THIS.PERSONPRO [J]);

}

Data = baos.tobytearray ();

Baos.close ();

dos.close ();

}

Catch (Exception E) {

Return

NULL;

}

Return Data;

}

public

Void ChangeFrombyteArray (

BYTE [] data) {

Try {

ByteArrayinputStream Bais =

New ByteArrayInputStream (data);

DataInputStream DIS =

New DataInputStream (bais);

FOR

INT K = 0; K

THIS.PERSONPRO [K] = dishdutf ();

}

Bais.Close ();

Dis.close ();

}

Catch (Exception E) {

}

}

Public String getPerson

INT m) {

Return

this.PersonPro [M];

}

Public String getListName

INT recordid) {

Return

This.PersonPro [0];

}

}

/ / ========================= ========================= ==========

/ / =============================================================================================================================================== ================ Package Messagemidlet;

Import javax.microedition.lcdui. *;

Import java.io. *;

public

Class MenumIdlet Extends List Implements CommandListener {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

/ ** constructor * /

Public meNumIdlet () {

Super

'Address Book', List.Implicit;

FOR

INT i = 0; I

THIS.APpend (Pubclass.Get_Menulist (i), Pubclass.createImage

'/images/tel.png');

}

// Constructor button

Pubclass.selectCommand =

New Command

'Select', Command.Screen, 2);

Pubclass.exitCommand =

New Command

'Leave', Command.exit, 1);

// Add listener

This.Addcommand (Pubclass.exitCommand);

This.Addcommand (Pubclass.selectCommand);

this.setcommandlistener

THIS);

}

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.selectcommand) {

INT SelectItem =

THIS.GetSelectedIndex ();

// Try not to use Switch, use IF to increase speed, although it is trouble, experience income

IF (selectItem == 0) {

Pubclass.Return_mainmidlet ();

}

IF (selectItem == 1) {

Pubclass.Return_Aboutmidlet ();

}

}

//drop out

IF (c == pubclass.exitcommand) {

Messagemidlet.quitApp ();

}

}

}

/ / ========================= ========================= ==========

// ============================================================================================================================================================================================================================= =========================Pickage Messagemidlet;

Import javax.microedition.midlet. *;

Import javax.microedition.lcdui. *;

Import javax.microedition.lcdui.command;

Import javax.microedition.lcdui.displayable;

public

Class Aboutmidlet Extends Form IMPLEments COMMANDLISTENER {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

/ ** constructor * /

Public Aboutmidlet () {

Super

');

THIS.SETTILE (

'About the author');

StringItem StringItem =

NEW STRINGITEM

'about the author',

'01 Netcom (2) No. 02. Name: Sukey. Copyright: SuKey. ');

THIS.APpend (StringItem);

// Constructor button

Pubclass.MenuCommand =

New Command

'Home Catalog', Command.screen, 1);

Pubclass.exitCommand =

New Command

'Leave', Command.back, 1);

// Add listener

This.Addcommand (Pubclass.MenuCommand);

This.Addcommand (Pubclass.exitCommand);

this.setcommandlistener

THIS);

}

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.menucommand) {

Pubclass.Return_MenumIdlet ();

}

IF (c == pubclass.exitcommand) {

Messagemidlet.quitApp ();

}

}

}

/ / ========================= ========================= ==========

/ / ================================================================================================================================================================================= ================ Package Messagemidlet;

//

Import javax.microedition.lcdui. *;

public

Class mainmidlet extends list imports commandListener {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

/ ** constructor * /

Public mainmidlet () {

Super

'Address Book', List.Implicit;

// Display list

FOR

INT i = 0; I

THIS.APpend (Pubclass.Get_mainlist (i), Pubclass.createImage

'/images/tel.png');

}

// Constructor button

Pubclass.selectCommand =

New Command

'Select', Command.ok, 1);

Pubclass.MenuCommand =

New Command

'Home Catalog', Command.exit, 2);

// Add listener

This.Addcommand (Pubclass.selectCommand);

This.Addcommand (Pubclass.MenuCommand);

this.setcommandlistener

THIS);

}

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.selectcommand) {

INT SelectItem =

THIS.GetSelectedIndex ();

// Try not to use Switch, use IF to increase speed, although it is trouble, experience income

IF (selectItem == 0) {

Pubclass.Return_PersonListMIDlet ();

}

IF (selectItem == 1) {

Pubclass.Return_Searchmidlet ();

}

IF (selectItem == 2) {

Pubclass.Return_AddPersonMidlet ();

}

IF (selectItem == 3) {

}

}

IF (c == pubclass.menucommand) {

Pubclass.Return_MenumIdlet ();

}

}

}

/ / ========================= ========================= ========== / / ================================================================================== =====================================================================================================================================================

Package messagemidlet;

Import javax.microedition.lcdui. *;

Import javax.microedition.rms. *;

public

Class addpersonmidlet extends form imports commandlistener {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

/ ** constructor * /

Public AddPersonMidlet () {

Super

');

THIS.SETTILE (

'add contact');

FOR

INT i = 0; I

THIS.APpend (Pubclass.Person [I]);

// Constructor Pubclass.exitCommand =

New Command

'Return', Command.ok, 1); Pubclass.okcommand =

New Command

'Save', Command.back, 2);

// Add listener

This.Addcommand (Pubclass.exitCommand);

This.Addcommand (Pubclass.okCommand);

this.setcommandlistener

THIS);

// Add record

Private

Void AddRecord () {RecordStore RS =

NULL; RS = Pubclass.Open ();

Try {

// Get the textfield each straight, save String in an array [] getString =

NEW STRING [Pubclass.Length];

FOR

INT i = 0; I

// Construct the Personclass instance personclass personclass =

NEW PERSONCLASS (); personclass.write (getString);

Byte [] data = personclass.changetobyteaRray ();

INT recordid = personclass.getRecordId ();

IF (RecordID! = -1) {RS.SetRecord (RecordID, Data, 0, Data.Length);}

Else {

// Add Record Recordid = rs.addRecord (Data, 0, Data.Length);} setget.setdelid (0); mainmidlet mainmidlet =

New mainmidlet (); pubclass.alert

'Added successfully! Return ....... ', mainmidlet;}

Catch (Exception E) {pubclass.alert

'Add contact failed');}}

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.okcommand) {

// Judgment at least to fill in the name

IF (Pubclass.Person [0] .getstring () ==

Null || Pubclass.Person [0] .getstring () ==

'') {pubclass.alert

'At least to fill in the name');

Else {

// Add record addRecord ();}}

IF (c == pubclass.exitcommand) {pubclass.return_mainmidlet ();}}}

/ / ========================= ========================= ==========

/ / ========================= ========================================================================================================================================================== ==============================================================================00;

public

Class PersonListMidlet Extends List ImmandListener {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

Private personclass personclass =

New persons ();

public

Int [] RecordIDS;

/ ** constructor * /

Public personListMidlet () {super

'Contact List', list.implicit; personList ();

// Constructor button Pubclass.selectCommand =

New Command

'View', Command.Screen, 2); Pubclass.exitCommand = New Command

'Edit', Command.exit, 1);

// Add listener

This.Addcommand (Pubclass.exitCommand);

This.Addcommand (Pubclass.selectCommand);

this.setcommandlistener

THIS);

//user list

public

Void personList () {recordstore =

NULL; RS = Pubclass.Open ();

Try {

Byte [] DATA;

// Establish an enumeration, take the record replaromeration re = rs.enumerateRecords

NULL,

NULL,

FALSE);

// Judgment whether it is recorded

IF (re.hasnextelement ()) {

INT Records = Re.numRecords ();

// Number of records replandis =

New

Int [Records];

// RecordID record array

FOR

INT i = 0; I

/ / Save ID Data = rs.getRecord (RecordIDS [I]); Personclass.changefrombyTearray (DATA);

THIS.APPEND (

'' Personclass.getPerson (0)

'', Pubclass.createImage

'/Images/per.png'))));

// Insert this RECORD name} setget.setistrue

True);

Else {

THIS.APPEND (

'Haven't added contact?',

NULL); setget.setistrue

False);}}

Catch (Exception E) {}}

// Global Variable ID

Private

Void setgetId () {

INT ITEMID =

THIS.GetSelectedIndex (); setget.setid (RecordIDS [itemID]);

// Global variable Delid

Private

Void setgetdelid () {

INT ITEMID =

this.getSelectedIndex (); setget.setdelid (RecordIDS [itemid]);

Private

void setgetmodid () {

INT ITEMID =

THIS.GetSelectedIndex (); setget.setmodid (RecordIDS [itemid]);

/ / Tip information and return

public

void alernone () {mainmidlet mainmidlet =

New mainmidlet (); pubclass.alert

'Uncomfortable', mainmidlets;

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.exitcommand) {

IF (setget.getistrue ()) {

this.setgetdelid ();

THIS.SETGETMODID (); pubclass.return_operateemIdlet ();

Else {alernone ();}}

IF (c == pubclass.selectcommand) {

IF (setget.getistrue ()) {

This.SetGetId (); pubclass.return_Persondetailmidlet ();} else {confernone ();}}}}

/ / ========================= ========================= ==========

// ========================= Searchmidlet lookup class ===================== ============ package messagemidlet; import javax.microedition.midlet *;. import javax.microedition.lcdui *;. import javax.microedition.lcdui.Command; import javax.microedition.lcdui.Displayable ;

public

Class searchMidlet Extends textbox imports commandlistener {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

/ ** constructor * /

Public searchMidlet () {super

'Find contacts',

'', 256, 0);

// Constructor button Pubclass.MenuCommand =

New Command

'Find', Command.Screen, 1); Pubclass.okCommand =

New Command

'Home Catalog', Command.back, 1);

// Add listener

This.Addcommand (Pubclass.MenuCommand);

This.Addcommand (Pubclass.okCommand);

this.setcommandlistener

THIS);

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.okcommand) {pubclass.return_MenumIdlet ();

IF (c == pubclass.menucommand) {

// Set the global variable setget.setstr

THIS.GETSTRING ()); Pubclass.Return_SearchOutmidlet ();}}}

/ / ========================= ========================= ========== / / ========================================================================== ====================================================================================================================== ;

public

Class searchMidlet extends list imports commandListener {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

Private personclass personclass =

New persons ();

public

Int [] RecordIDS;

/ ** constructor * /

Public searchoutmidlet () {super

'Find Result', list.implicit; personList ();

// Constructor button Pubclass.selectCommand =

New Command

'View', Command.Screen, 2); Pubclass.ExitCommand =

New Command

'Edit', Command.exit, 1);

// Add listener

This.Addcommand (Pubclass.exitCommand);

This.Addcommand (Pubclass.selectCommand);

this.setcommandlistener

THIS);

//user list

public

Void personList () {recordstore =

NULL; RS = Pubclass.Open ();

Try {

Byte [] DATA;

// Match Recordfilter RF =

NEW namefilter ();

// Establish an enumeration, take the record replaromeration re = rs.enumerateRecords (RF,

NULL,

FALSE);

// Judgment whether it is recorded

IF (re.hasnextelement ()) {

INT Records = Re.numRecords ();

// Number of records replandis =

New

Int [Records];

// RecordID record array

FOR

INT i = 0; I

/ / Save ID Data = rs.getRecord (RecordIDS [i]); Personclass.changefrombyteArray (DATA); this.Append

'' Personclass.getPerson (0)

'', Pubclass.createImage

'/Images/per.png'))));

// Insert this RECORD name} setget.setistrue

True);

Else {

THIS.APPEND (

'Sorry, I didn't find',

NULL); setget.setistrue

False);}}

Catch (Exception E) {}}

// Global Variable ID

Private

Void setgetId () {

INT ITEMID =

THIS.GetSelectedIndex (); setget.setid (RecordIDS [itemID]);

// Global variable MODID

Private

void setgetmodid () {

INT ITEMID =

THIS.GetSelectedIndex (); setget.setmodid (RecordIDS [itemid]);

// Global variable Delid

Private

Void setgetdelid () {

INT ITEMID =

this.getSelectedIndex (); setget.setdelid (RecordIDS [itemid]);

/ / Tip information and return

public

void alernone () {mainmidlet mainmidlet =

New mainmidlet (); pubclass.alert

'Uncomfortable', mainmidlets;

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.exitcommand) {

IF (setget.getistrue ()) {

THIS.SETGETMODID ();

THIS.SETGETDELID (); Pubclass.Return_operateMIDlet ();

Else {alernone ();}}

IF (c == pubclass.selectcommand) {

IF (setget.getistrue ()) {

THIS.SETGETID (); Pubclass.Return_Persondetailmidlet ();

Else {alernone ();}}}}

Class Namefilter Implements Recordfilter {

Public Boolean Matches

Byte [] Candidate) {DataInputStream Person =

New DataInputStream

New ByteArrayInputStream (Candidate)); String PersoncName =

'';

Try {personcname = person.Readutf ();}

Catch (Exception E) {} personclass personclass =

New persons ();

IF (PersoncName.equals (setget.getstr ())))

Return

True;

Else

Return

False;}}

/ / ========================= ========================= ========== / / ============================================================================================================================================================================================= ===========================================================================================================================================================001

public

Class Persondetailmidlet Extends Form IMPLEments CommandListener {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

/ ** constructor * /

Public persdetailmidlet () {super

');

THIS.CONSTRUCTORLIST ();

// Constructor button Pubclass.selectCommand =

New Command

'Back', Command.Screen, 2); Pubclass.ExitCommand =

New Command

'Main Catalog', Command.exit, 1);

// Add listener

This.Addcommand (Pubclass.exitCommand);

This.Addcommand (Pubclass.selectCommand);

this.setcommandlistener

THIS);

/ / Conformal List, display details

Private

Void constructorlist () {

Try {

THIS.GETPERSONDETAIL ();

Catch (RecordStoreException EX) {}}

/ / Bind the corresponding ID data and display

Private

Void getPersondetail () throws recordormoreException {recordstore =

NULL;

// Open the database RS = pubclass.open ();

// Establish an enumeration and obtain the details of the corresponding ID

Try {

Byte [] data; recording re = rs.enumerateRecords

NULL,

NULL,

False); DATA = rs.getRecord (setget.getid ());

// Reconfigure and convert Byte into string type Personclass Personclass =

New personclass (); personclass.changefrombytearray (data); // Reset User ID

INT RecordId = rs.getnexTrecordId ();

/ / Assign a value for the corresponding attribute

FOR

INT i = 0; i

THIS.APpend (Pubclass.Persondetail [i]); Pubclass.Persondetail [i] .Settext (Personclass.getPerson (i));}

/ / Set the title as the username

This.SetTitle (Personclass.GetPerson (0));

Catch (RecordStorenotopenexception EX) {}}

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.selectcommand) {pubclass.return_PersonListMIDlet ();

IF (c == pubclass.exitCommand) {pubclass.return_menumidlet ();}}}}}

/ / ========================= ========================= ==========

/ / ========================= OperateMIDlet operation contact person (only delete function) ============= =================== Package messagemidlet; import javax.microedition.midlet. *; import javax.microedition.lcdui. *; import javax.microedition.rms. *;

public

Class OperateMidlet Extends List Implements CommandListener {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

/ ** constructor * /

Public OperateMidlet () {super

'Contact', list.implicit;

FOR

INT i = 0; i

THIS.Append (Pubclass.get_operateList (i), Pubclass.createImage

'/images/edit.png'));

// Constructor Pubclass. gamCommand = New Command

'Select', Command.Screen, 2); Pubclass.MenuCommand =

New Command

'Main Catalog', Command.exit, 1);

// Add listener

This.Addcommand (Pubclass.MenuCommand);

This.Addcommand (Pubclass. gazkerCommand);

this.setcommandlistener

THIS);

/ / Delete the specified record

public

Void Del

INT Delid) {personclass personclass =

New persons (); RecordStore RS =

NULL; RS = Pubclass.Open ();

Try {

// Judgment whether it is recorded

IF (rs.getnumRecords () <1) {pubclass.alert

'Not added yet! Return ....... ');

Else {

// bug rs.deleteRecord (Delid); AlertInfo

'successfully deleted! Return ....... ');}}

Catch (Exception E) {alertinfo

'failed to delete! Return ....... ');}}

/ / All delete records

public

Void deLall () {personclass personclass =

New persons (); RecordStore RS =

NULL; RS = Pubclass.Open ();

// Judgment whether it is recorded

Try {

IF (rs.getnumRecords () <1) {pubclass.alert

'Not added yet! Return ....... ');

Else {

// Conquer the Recordenumeration instance, remove the record replaromeration re = rs.enumerateRecords

NULL,

NULL,

FALSE);

/ / According to ID, loop deletion

While (Re.hasNexTelement ()) {

INT RecoidId = Re.nexTrecordId (); rs.deleteRecord (RecoidId);} alertinfo

'successfully deleted! Return ....... ');}}

Catch (Exception E) {alertinfo

'failed to delete! Return ....... ');}}

public

Void Alertinfo (String Info) {personListMidlet personListMIDlet =

New personlistmidlet (); Pubclass.alert (in, fo, personlistmidlet);

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.menucommand) {pubclass.return_menumIdlet ();

IF (c == pubclass. gazkercommand) {

INT SelectItem =

THIS.GetSelectedIndex ();

// Try not to use Switch, use IF to increase speed, although it is trouble, experience income

IF (selectitem == 0) {pubclass.return_modifyPERSONMIDLET ();} if (selecttem == 1) {DEL (setget.getdelid ()); setget.setdelid (0);}

IF (selecttem == 2) {deLall (); setget.SetDelid (0);}}}}

/ / ========================= ========================= ==========

/ / ==================================================================================================================================== ================= Package Messagemidlet; import javax.microedition.lcdui. *; import javax.microedition.rms. *;

public

Class ModifyPersonmidlet Extends form imports commandlistener {

// Construct a public class instance

Private Pubclass Pubclass =

New Pubclass ();

/ ** constructor * /

Public ModifyPersonmidlet () {Super

');

Try {

THIS.GETPERSONDETAIL ();

Catch (RecordStoreException EX) {}

// Constructor Pubclass.exitCommand =

New Command

'Home Catalog', Command.ok, 1); Pubclass.OkCommand =

New Command

'Modify', Command.Back, 2);

// Add listener

This.Addcommand (Pubclass.exitCommand);

This.Addcommand (Pubclass.okCommand);

this.setcommandlistener

THIS);

/ / Bind the corresponding ID data and display

Private

Void getPersondetail () throws recordormoreException {recordstore =

NULL;

// Open the database RS = pubclass.open ();

// Establish an enumeration and obtain the details of the corresponding ID

Try {

Byte [] data; recording re = rs.enumerateRecords

NULL,

NULL,

False); DATA = rs.getRecord (setget.getmodid ()); // Reconfiguration, and convert Byte to string type Personclass Personclass =

NEW PERSONCLASS (); Personclass.changefrombyteaRray (data);

// Reset the user ID

INT RecordId = rs.getnexTrecordId ();

/ / Assign a value for the corresponding attribute

FOR

INT i = 0; I

THIS.APpend (Pubclass.Person [i]); Pubclass.Person [i] .setstring (Personclass.getPerson (i));}

/ / Set the title as the username

THIS.SETTILE (

'Modify' Personclass.getPerson (0));

Catch (RecordStorenotopenexception EX) {} rs.closecordstore ();}

// Modify the contact

public

Void updataperson () {recordstore =

NULL; RS = Pubclass.Open ();

Try {

// Get the textfield each straight, save String in an array [] getString =

NEW STRING [Pubclass.Length];

FOR

INT i = 0; i

// Construct the Personclass instance personclass personclass =

NEW PERSONCLASS (); personclass.write (getString);

Byte [] data = personclass.changetobyteaRray ();

INT recordid = personclass.getRecordId ();

IF (RecordID! = -1) {RS.SetRecord (RecordID, Data, 0, Data.Length);}

Else {

// Modify the record RS.SetRecord (setget.getmodid (), DATA, 0, DATA.LENGTH);

//rs.seTrecord (setget.getmodid (), DATA, 0, DATA.LENGTH; Personclass.SetRecordId (RecordId);} setget.setmodid (0); personlistmidlet personListMIDlet =

New personlistmidlet (); pubclass.alert

'Successfully modified! Return ....... ', PersonListMidlet;

Catch (Exception E) {personListMidlet PersonListMIDlet =

New personlistmidlet (); pubclass.alert

'Modify Fail', PersonListMidlet;}}

public

Void CommandAction (Command C, Displayable D) {

IF (c == pubclass.exitcommand) {pubclass.return_menumIdlet ();

IF (c == pubclass.okcommand) {

// Judgment at least to fill in the name IF (Pubclass.Person [0] .getstring () ==

Null || Pubclass.Person [0] .getstring () ==

'') {pubclass.alert

'At least to fill in the name');

Else {

THIS.UPDataPerson ();}}}}

/ / ========================= ========================= ==========

转载请注明原文地址:https://www.9cbs.com/read-89335.html

New Post(0)