|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
APPLICATION MEMO EN J2ME POUR PALM TREO 500
Information sur la source
Description
Bonjour, Je débute en J2ME et je viens de m'acheter un Palm Treo 500 qui tourne sous Windows Mobile 6. Pour une raison que j'ignore, Palm n'a pas porté sous Windows Mobile l'application "memo" qui est celle que j'utilisais le plus sur mes "anciens Palm". J'ai donc réalisé une petite appli J2ME qui permet de saisir des mémos, de modifier et de faire des recherches parmi les mémos. Les mémos sont stockés en Record Store.
Source
- package memo;
-
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.util.Vector;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.Display;
-
- import javax.microedition.midlet.MIDlet;
- import javax.microedition.lcdui.*;
- import javax.microedition.rms.*;
-
-
- public class Screen extends MIDlet {
-
- /** A generic way of indicating whether startApp() has previously been called. */
- private Display display;
- private Screen midlet;
- private List memoList;
- private Vector memoMap;
- private RecordStore memoStore;
- private int nbMemo = 0;
- private String lastSearchString = "";
-
- /** Priority of commands relative to others of the same type. */
- private static final int COMMAND_PRIORITY = 2;
- private static final int COMMAND_PRIORITY_1 = 1;
-
- /** Command specified to initiate the termination of the MIDlet. */
-
- private static final Command CMD_EXIT =
- new Command("Exit", Command.EXIT, COMMAND_PRIORITY);
-
- /** Command specified to initiate the launch of the TextEditor screen. */
- private static final Command CMD_NEW =
- new Command("New", Command.ITEM, COMMAND_PRIORITY_1);
-
- private static final Command CMD_EDIT =
- new Command("Edit", Command.ITEM, COMMAND_PRIORITY);
-
- private static final Command CMD_SEARCH =
- new Command("Search", Command.ITEM, COMMAND_PRIORITY);
-
- private static final Command CMD_DONE =
- new Command("Done", Command.ITEM, COMMAND_PRIORITY);
-
- private static final Command CMD_DELETE =
- new Command("Delete", Command.ITEM, COMMAND_PRIORITY);
-
-
- /*
- * Update an existing memo into the RecordStore
- */
- public void updateMemo(Memo memo) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream os = new DataOutputStream(baos);
- try {
- os.writeUTF(memo.getText());
- os.close();
- } catch (IOException e) {
- System.out.println(e);
- }
- byte[] data = baos.toByteArray();
- try {
- memoStore.setRecord(memo.getId(), data, 0, data.length);
- } catch (Exception e) {
- System.err.println(e);
- }
- }
-
- /*
- * Stores a Memo object into the RecordStore.
- * Returns the Id of the created Record.
- */
- public int storeMemo(Memo memo) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream os = new DataOutputStream(baos);
- int Id = -1;
- try {
- os.writeUTF(memo.getText());
- os.close();
- } catch (IOException e) {
- System.out.println(e);
- }
- byte[] data = baos.toByteArray();
- try {
- Id = memoStore.addRecord(data, 0, data.length);
- } catch (Exception e) {
- System.err.println(e);
- }
- return Id;
- }
-
- /*
- * reads the record #Id from the RecordStore and fill a Memo object with these
- * bytes.
- * Returns the created Memo object
- */
- public Memo getMemo(int Id) {
- Memo memo = null;
- try {
- byte[] bytes = memoStore.getRecord(Id);
- DataInputStream is = new DataInputStream(new ByteArrayInputStream(bytes));
- String texte = is.readUTF();
- memo = new Memo(texte,Id);
- //memo = new Memo("Default text "+Id);
- } catch (Exception e) {
- System.err.println(e);
- }
- return memo;
- }
-
-
- /*
- * Deletes the record #Id from the RecordStore
- */
- public void deleteMemo(int Id) {
- try {
- memoStore.deleteRecord(Id);
- } catch (Exception e) {
- System.err.println(e);
- }
- }
-
- public void startApp() {
- if (display == null) {
- // First time we've been called.
- display=Display.getDisplay(this);
- midlet = this;
- // create the List of all memos
- memoMap = new Vector();
-
- // create the List of Memo titles being diplayed on the main screen
- memoList = new List("memo",List.IMPLICIT);
-
- // Open and read the record Store
- memoStore = null;
- try {
- RecordEnumeration recordEnum = null;
- memoStore = RecordStore.openRecordStore(Memo.MEMO_STORE_NAME, true,RecordStore.AUTHMODE_ANY,true);
- recordEnum = memoStore.enumerateRecords(null,null,false);
- while (recordEnum.hasPreviousElement()) {
- int Id = recordEnum.previousRecordId();
- // System.out.println("Reading Record Id = "+Id+ " from Record Store");
- Memo memo = getMemo(Id);
- memoMap.addElement(memo);
- memoList.append(memo.getTitle(),null);
- nbMemo++;
- }
- } catch (RecordStoreException e) {
- System.err.println(e);
- }
- /*
- * Creates the menu of the memo application
- */
- memoList.addCommand(CMD_EXIT);
- memoList.addCommand(CMD_NEW);
- memoList.addCommand(CMD_EDIT);
- memoList.addCommand(CMD_SEARCH);
- memoList.addCommand(CMD_DELETE);
-
- /*
- * Process the actions associated with the menus
- */
- memoList.setCommandListener(new CommandListener() {
- public void commandAction(Command c, Displayable d) {
- /*
- * Creation of a new memo
- */
- if (c == CMD_NEW) {
- // create a new memo object. The Id is not known yet. It will be
- // known only after the memo has been inserted into the Record Store
- Memo memo = new Memo("",-1);
- int Id = storeMemo(memo);
- memo.setId(Id);
- // System.out.println("Creating memo Id = "+Id);
- memoMap.addElement(memo);
- nbMemo++;
- memoList.append(memo.getTitle(),null);
- memoList.setSelectedIndex(nbMemo-1,true);
- /*
- * Switch to the screen allowing the user to enter the text of the
- * memo
- */
- TextEditor textEditor = new TextEditor(midlet,"");
- display.setCurrent(textEditor);
-
- /*
- * Edit an existing memo
- */
- } else if (c == CMD_EDIT) {
- if (nbMemo > 0) {
- int i = memoList.getSelectedIndex();
- Memo memo = (Memo)memoMap.elementAt(i);
- TextEditor textEditor = new TextEditor(midlet,memo.getText());
- display.setCurrent(textEditor);
- }
-
- } else if (c == CMD_DELETE) {
- /*
- * Delete a memo
- */
- if (nbMemo > 0) {
- int index = memoList.getSelectedIndex();
- Memo memo = (Memo)memoMap.elementAt(index);
- deleteMemo(memo.getId());
- memoMap.removeElementAt(index);
- memoList.delete(index);
- nbMemo--;
- display.setCurrent(memoList);
- }
- } else if (c == CMD_SEARCH) {
- /*
- * Create a search box to entering the box to search
- */
- SearchBox searchEditor = new SearchBox(midlet,lastSearchString);
- display.setCurrent(searchEditor);
-
- } else if (c == CMD_DONE) {
- /*
- * The system was displaying only the list of memo containing
- * a string to search. The Done command restores the normal
- * diplay and menus.
- */
- display.setCurrent(memoList);
- memoList.removeCommand(CMD_DONE);
- memoList.removeCommand(CMD_EDIT);
- memoList.removeCommand(CMD_DELETE);
-
- memoList.addCommand(CMD_EXIT);
- memoList.addCommand(CMD_NEW);
- memoList.addCommand(CMD_EDIT);
- memoList.addCommand(CMD_SEARCH);
- memoList.addCommand(CMD_DELETE);
- /*
- * Rebuild the full memo list
- */
- memoList.deleteAll();
- memoMap.removeAllElements();
- nbMemo = 0;
- try {
- RecordEnumeration recordEnum = null;
- recordEnum = memoStore.enumerateRecords(null,null,false);
- while (recordEnum.hasPreviousElement()) {
- int Id = recordEnum.previousRecordId();
- System.out.println("Reading Record Id = "+Id+ " from Record Store");
- Memo memo = getMemo(Id);
- memoMap.addElement(memo);
- memoList.append(memo.getTitle(),null);
- nbMemo++;
- }
- } catch (RecordStoreException e) {
- System.err.println(e);
- }
- display.setCurrent(memoList);
-
- } else if (c == CMD_EXIT) {
- /*
- * exit the program
- */
- destroyApp(true);
- notifyDestroyed();
-
- }
-
- }
- });
-
- display.setCurrent(memoList);
- }
- }
-
- /**
- * This must be defined but no implementation is required because the MIDlet
- * only responds to user interaction.
- */
- public void pauseApp() {
- }
-
- /**
- * No further implementation is required because the MIDlet holds no
- * resources that require releasing.
- *
- * @param unconditional is ignored.
- */
- public void destroyApp(boolean unconditional) {
- try {
- memoStore.closeRecordStore();
- } catch (Exception e) {
- System.err.println(e);
- }
- }
-
- /**
- * A convenience method for exiting.
- */
- public void exitRequested(){
- destroyApp(false);
-
- /*
- * notifyDestroyed() tells the scheduler that this MIDlet is now in a
- * destroyed state and is ready for disposal.
- */
- notifyDestroyed();
- }
-
- /*
- * This method is called by the TextEditor object when the user has selected either
- * OK or CANCEL menu.
- * It updates the text of the memo object with the text entered by the user
- */
- public void textEditorDone(String s) {
- if (s != null) {
- int index = memoList.getSelectedIndex();
- Memo memo = (Memo)memoMap.elementAt(index);
- memo.setText(s);
- memoList.delete(index);
- memoList.insert(index, memo.getTitle(),null);
- updateMemo(memo);
- }
- display.setCurrent(memoList);
- }
-
- /*
- * This method is called by the SearchBox object when the user has selected either
- * OK or CANCEL menu.
- * It replaces the list of memos being displayed by a new list containing only those
- * memos containing the searched text.
- * Additionally, it creates a new set a menus (mainly, a DONE menu allowing to come
- * back to the full memo list
- */
-
- public void searchBoxDone(String s) {
- if (s != null) {
- // afficher uniquement la liste des notes corresondant à la recherche
- lastSearchString = s;
- memoList.deleteAll();
- memoMap.removeAllElements();
- nbMemo = 0;
- try {
- RecordEnumeration recordEnum = null;
- recordEnum = memoStore.enumerateRecords(null,null,false);
- while (recordEnum.hasPreviousElement()) {
- int Id = recordEnum.previousRecordId();
- System.out.println("Reading Record Id = "+Id+ " from Record Store");
- Memo memo = getMemo(Id);
- if (memo.contains(s)) {
- memoMap.addElement(memo);
- memoList.append(memo.getTitle(),null);
- nbMemo++;
- }
- }
- } catch (RecordStoreException e) {
- System.err.println(e);
- }
- memoList.removeCommand(CMD_NEW);
- memoList.removeCommand(CMD_EXIT);
- memoList.removeCommand(CMD_SEARCH);
- memoList.addCommand(CMD_DONE);
- display.setCurrent(memoList);
- }
- }
-
- }
-
package memo;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Vector;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class Screen extends MIDlet {
/** A generic way of indicating whether startApp() has previously been called. */
private Display display;
private Screen midlet;
private List memoList;
private Vector memoMap;
private RecordStore memoStore;
private int nbMemo = 0;
private String lastSearchString = "";
/** Priority of commands relative to others of the same type. */
private static final int COMMAND_PRIORITY = 2;
private static final int COMMAND_PRIORITY_1 = 1;
/** Command specified to initiate the termination of the MIDlet. */
private static final Command CMD_EXIT =
new Command("Exit", Command.EXIT, COMMAND_PRIORITY);
/** Command specified to initiate the launch of the TextEditor screen. */
private static final Command CMD_NEW =
new Command("New", Command.ITEM, COMMAND_PRIORITY_1);
private static final Command CMD_EDIT =
new Command("Edit", Command.ITEM, COMMAND_PRIORITY);
private static final Command CMD_SEARCH =
new Command("Search", Command.ITEM, COMMAND_PRIORITY);
private static final Command CMD_DONE =
new Command("Done", Command.ITEM, COMMAND_PRIORITY);
private static final Command CMD_DELETE =
new Command("Delete", Command.ITEM, COMMAND_PRIORITY);
/*
* Update an existing memo into the RecordStore
*/
public void updateMemo(Memo memo) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(baos);
try {
os.writeUTF(memo.getText());
os.close();
} catch (IOException e) {
System.out.println(e);
}
byte[] data = baos.toByteArray();
try {
memoStore.setRecord(memo.getId(), data, 0, data.length);
} catch (Exception e) {
System.err.println(e);
}
}
/*
* Stores a Memo object into the RecordStore.
* Returns the Id of the created Record.
*/
public int storeMemo(Memo memo) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(baos);
int Id = -1;
try {
os.writeUTF(memo.getText());
os.close();
} catch (IOException e) {
System.out.println(e);
}
byte[] data = baos.toByteArray();
try {
Id = memoStore.addRecord(data, 0, data.length);
} catch (Exception e) {
System.err.println(e);
}
return Id;
}
/*
* reads the record #Id from the RecordStore and fill a Memo object with these
* bytes.
* Returns the created Memo object
*/
public Memo getMemo(int Id) {
Memo memo = null;
try {
byte[] bytes = memoStore.getRecord(Id);
DataInputStream is = new DataInputStream(new ByteArrayInputStream(bytes));
String texte = is.readUTF();
memo = new Memo(texte,Id);
//memo = new Memo("Default text "+Id);
} catch (Exception e) {
System.err.println(e);
}
return memo;
}
/*
* Deletes the record #Id from the RecordStore
*/
public void deleteMemo(int Id) {
try {
memoStore.deleteRecord(Id);
} catch (Exception e) {
System.err.println(e);
}
}
public void startApp() {
if (display == null) {
// First time we've been called.
display=Display.getDisplay(this);
midlet = this;
// create the List of all memos
memoMap = new Vector();
// create the List of Memo titles being diplayed on the main screen
memoList = new List("memo",List.IMPLICIT);
// Open and read the record Store
memoStore = null;
try {
RecordEnumeration recordEnum = null;
memoStore = RecordStore.openRecordStore(Memo.MEMO_STORE_NAME, true,RecordStore.AUTHMODE_ANY,true);
recordEnum = memoStore.enumerateRecords(null,null,false);
while (recordEnum.hasPreviousElement()) {
int Id = recordEnum.previousRecordId();
// System.out.println("Reading Record Id = "+Id+ " from Record Store");
Memo memo = getMemo(Id);
memoMap.addElement(memo);
memoList.append(memo.getTitle(),null);
nbMemo++;
}
} catch (RecordStoreException e) {
System.err.println(e);
}
/*
* Creates the menu of the memo application
*/
memoList.addCommand(CMD_EXIT);
memoList.addCommand(CMD_NEW);
memoList.addCommand(CMD_EDIT);
memoList.addCommand(CMD_SEARCH);
memoList.addCommand(CMD_DELETE);
/*
* Process the actions associated with the menus
*/
memoList.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
/*
* Creation of a new memo
*/
if (c == CMD_NEW) {
// create a new memo object. The Id is not known yet. It will be
// known only after the memo has been inserted into the Record Store
Memo memo = new Memo("",-1);
int Id = storeMemo(memo);
memo.setId(Id);
// System.out.println("Creating memo Id = "+Id);
memoMap.addElement(memo);
nbMemo++;
memoList.append(memo.getTitle(),null);
memoList.setSelectedIndex(nbMemo-1,true);
/*
* Switch to the screen allowing the user to enter the text of the
* memo
*/
TextEditor textEditor = new TextEditor(midlet,"");
display.setCurrent(textEditor);
/*
* Edit an existing memo
*/
} else if (c == CMD_EDIT) {
if (nbMemo > 0) {
int i = memoList.getSelectedIndex();
Memo memo = (Memo)memoMap.elementAt(i);
TextEditor textEditor = new TextEditor(midlet,memo.getText());
display.setCurrent(textEditor);
}
} else if (c == CMD_DELETE) {
/*
* Delete a memo
*/
if (nbMemo > 0) {
int index = memoList.getSelectedIndex();
Memo memo = (Memo)memoMap.elementAt(index);
deleteMemo(memo.getId());
memoMap.removeElementAt(index);
memoList.delete(index);
nbMemo--;
display.setCurrent(memoList);
}
} else if (c == CMD_SEARCH) {
/*
* Create a search box to entering the box to search
*/
SearchBox searchEditor = new SearchBox(midlet,lastSearchString);
display.setCurrent(searchEditor);
} else if (c == CMD_DONE) {
/*
* The system was displaying only the list of memo containing
* a string to search. The Done command restores the normal
* diplay and menus.
*/
display.setCurrent(memoList);
memoList.removeCommand(CMD_DONE);
memoList.removeCommand(CMD_EDIT);
memoList.removeCommand(CMD_DELETE);
memoList.addCommand(CMD_EXIT);
memoList.addCommand(CMD_NEW);
memoList.addCommand(CMD_EDIT);
memoList.addCommand(CMD_SEARCH);
memoList.addCommand(CMD_DELETE);
/*
* Rebuild the full memo list
*/
memoList.deleteAll();
memoMap.removeAllElements();
nbMemo = 0;
try {
RecordEnumeration recordEnum = null;
recordEnum = memoStore.enumerateRecords(null,null,false);
while (recordEnum.hasPreviousElement()) {
int Id = recordEnum.previousRecordId();
System.out.println("Reading Record Id = "+Id+ " from Record Store");
Memo memo = getMemo(Id);
memoMap.addElement(memo);
memoList.append(memo.getTitle(),null);
nbMemo++;
}
} catch (RecordStoreException e) {
System.err.println(e);
}
display.setCurrent(memoList);
} else if (c == CMD_EXIT) {
/*
* exit the program
*/
destroyApp(true);
notifyDestroyed();
}
}
});
display.setCurrent(memoList);
}
}
/**
* This must be defined but no implementation is required because the MIDlet
* only responds to user interaction.
*/
public void pauseApp() {
}
/**
* No further implementation is required because the MIDlet holds no
* resources that require releasing.
*
* @param unconditional is ignored.
*/
public void destroyApp(boolean unconditional) {
try {
memoStore.closeRecordStore();
} catch (Exception e) {
System.err.println(e);
}
}
/**
* A convenience method for exiting.
*/
public void exitRequested(){
destroyApp(false);
/*
* notifyDestroyed() tells the scheduler that this MIDlet is now in a
* destroyed state and is ready for disposal.
*/
notifyDestroyed();
}
/*
* This method is called by the TextEditor object when the user has selected either
* OK or CANCEL menu.
* It updates the text of the memo object with the text entered by the user
*/
public void textEditorDone(String s) {
if (s != null) {
int index = memoList.getSelectedIndex();
Memo memo = (Memo)memoMap.elementAt(index);
memo.setText(s);
memoList.delete(index);
memoList.insert(index, memo.getTitle(),null);
updateMemo(memo);
}
display.setCurrent(memoList);
}
/*
* This method is called by the SearchBox object when the user has selected either
* OK or CANCEL menu.
* It replaces the list of memos being displayed by a new list containing only those
* memos containing the searched text.
* Additionally, it creates a new set a menus (mainly, a DONE menu allowing to come
* back to the full memo list
*/
public void searchBoxDone(String s) {
if (s != null) {
// afficher uniquement la liste des notes corresondant à la recherche
lastSearchString = s;
memoList.deleteAll();
memoMap.removeAllElements();
nbMemo = 0;
try {
RecordEnumeration recordEnum = null;
recordEnum = memoStore.enumerateRecords(null,null,false);
while (recordEnum.hasPreviousElement()) {
int Id = recordEnum.previousRecordId();
System.out.println("Reading Record Id = "+Id+ " from Record Store");
Memo memo = getMemo(Id);
if (memo.contains(s)) {
memoMap.addElement(memo);
memoList.append(memo.getTitle(),null);
nbMemo++;
}
}
} catch (RecordStoreException e) {
System.err.println(e);
}
memoList.removeCommand(CMD_NEW);
memoList.removeCommand(CMD_EXIT);
memoList.removeCommand(CMD_SEARCH);
memoList.addCommand(CMD_DONE);
display.setCurrent(memoList);
}
}
}
Conclusion
En revanche, je n'ai pas trouvé le moyen de synchroniser les mémos avec un PC (en utilisant Active Sync). Si vous vous sentez de modifier le source et de le remettre sur le site, n'hésitez pas ... Thierry
Fichier Zip
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Java sur Palm Pilot [ par DrPhil ]
Bonjour,j'aimerai utilisé Java pour créer des programmes sur Palm Pilots...Que me faut-il ?Merci
J2ME et pocket pc 2003 [ par bob24 ]
Salut, Je dois programmer une appli en java pour pocket pc 2003 et je suis un peu perdu. On gros, on m'a fourni Device Depeloper d'IBM et on m'a dit d
J2ME Java pour la Mobilité!! mais comment? (ya même pas de Button)! [ par safisoft ]
Bonjour tout le monde; je sais pas au faite comment faire des bouttons (pas des Command) dans une application pour PocketPC, PDA.... (dispositifs 
j2me base de données dans un PDA palm [ par raymond59 ]
Salut à tous j'aimerais faire un programme en java qui dervait lire des infos dans la base de données de mon Palm (T5) spécialement les
J2ME - JarToPrc [ par Dobel ]
Salut à tous, Je recherche l'utilitaire JarToPrc permettant de passer du jar d'une application Java Micro Edition vers un .prc pour Palm. Le pr
Java [J2ME]-> Téléphone [ par stanilou ]
Salut, J'ai télécharger un programme en J2ME (java pour mobile et palm) qui est au format .jar or j'ai lus je ne sais où qu'il faut le
assembleur dans un code source java J2ME [ par kamikazz01 ]
Bonjour, je suis en train de programmer un petit utilitaire pour apprendre le J2ME, et j'aimerai inclure une routine assembleur. Cela est-ce possible
RMS J2ME et transfert sur PC [ par nara20 ]
Bonjour,J'utilise RMS pour stocker des données sur mon téléphone portable. Je voudrais savoir comment je peux transférer ses donn&
Un jeu en java pour telephone mobile [ par Format C ]
J'ai une idee de creer un jeu en java pour telephone mobile en utilisant j2me.Pour le debut, je je vais d'utiliser une emulator. Y at-il quelqu'u
midlet j2me ou est passé java.lang.Math.log [ par misterzinzin ]
bonjour, je vien de commencer la programmation de midlet (java pour mobile) et je ne trouva pas la fonction permettant de calculer des logarithme dans
|
Téléchargements
Logiciels à télécharger sur le même thème :
|