Blackberry JAVA DEVELOPMENT ENVIRONMENT - - CRYPTOGRAPHIC SMART CARD DRIVER - DEVELOPMENT GUIDE Troubleshooting Guide Page 70

  • Download
  • Add to my manuals
  • Print
  • Page
    / 286
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 69
70
BlackBerry Java Development Environment Development Guide
Store data persistently. > In the class for the objects that you want to store, implement the Persistable interface.
private static final class RestaurantInfo implements Persistable {
private String[] _elements;
public static final int NAME = 0;
public static final int ADDRESS = 1;
public static final int PHONE = 2;
public static final int SPECIALTY = 3;
public RestaurantInfo() {
_elements = new String[4];
for ( int i = 0; i < _elements.length; ++i) {
_elements[i] = new String("");
}
}
public String getElement(int id) {
return _elements[id];
}
public void setElement(int id, String value) {
_elements[id] = value;
}
}
Save an object. 1. Define an object.
The following code fragment creates a RestaurantInfo object and uses its set methods to define its
components.
RestaurantInfo info = new RestaurantInfo();
info.setElement(RestaurantInfo.NAME, namefield.getText());
info.setElement(RestaurantInfo.ADDRESS,addressfield.getText());
info.setElement(RestaurantInfo.PHONE, phonefield.getText());
info.setElement(RestaurantInfo.SPECIALTY, specialtyfield.getText());
2. Add the object to a vector object by invoking addElement().
_data.addElement(info);
3. Invoke setContents().
4. To save the updated data, invoke commit() on the PersistentObject.
5. Synchronize with the persistent object when making changes so that other threads cannot make changes
to the object at the same time.
synchronized(store) {
store.setContents(_data);
store.commit();
}
Task Steps
Page view 69
1 2 ... 65 66 67 68 69 70 71 72 73 74 75 ... 285 286

Comments to this Manuals

No comments