Presentation is loading. Please wait.

Presentation is loading. Please wait.

Detecting Changes  ItemStateListener interface – detect changes in internal state of an Item  new selection made in a ChoiceGroup  adjusted value of.

Similar presentations


Presentation on theme: "Detecting Changes  ItemStateListener interface – detect changes in internal state of an Item  new selection made in a ChoiceGroup  adjusted value of."— Presentation transcript:

1 Detecting Changes  ItemStateListener interface – detect changes in internal state of an Item  new selection made in a ChoiceGroup  adjusted value of interactive Gauge  modified/entered value in TextField  modified/entered value in DateField

2 Detecting Changes  ItemStateListener interface – detect changes in internal state of an Item  new selection made in a ChoiceGroup  adjusted value of interactive Gauge  modified/entered value in TextField  modified/entered value in DateField  The interface methods: interface ItemStateListener { public void itemStateChanged(Item item); }

3 Detecting Changes Example class MyMIDlet implements ItemStateListener { public void startApp() { mainScreen = new Form(“Welcome”);... build form/add widgets... mainScreen.setItemStateListener(this); } public void itemStateChanged(Item item) { if (item == theTextField) {...... } else if (item == theChoiceGroup) {............ }

4 Lab Exercise  Create an application that echoes the user input in a TextField

5 User Interface Summary Displayable ScreenCanvas FormAlertListTextbox Item DateFieldImageItemTextFieldStringItemGaugeChoiceGroup

6 User Interface Summary  Use appropriate number and size of widgets  Develop consistent interface using  Command Types – Command.EXIT/OK/CANCEL  Input Constraints – TextField.NUMERIC/PASSWORD/EMAILADDR  Fit Policy – Choice.TEXT_WRAP_ON/OFF/DEFAULT  Use Alert screens to confirm execution or report errors  Give the option to cancel the execution of an operation  Take into account the differences between devices  e.g. different default sizes for images used as choice thumbnails

7 Persistent Storage  Record Stores  mini databases – represent data as byte records  Record Management System (RMS) API  Files and Directories  FileConnection API  Contacts and Calendars  Personal Information Management (PIM) API

8 RMS vs FileConnection API  FileConnection  familiar (simpler) to use  provides access to images, sounds, etc.  needs security privileges  may not be supported on older devices

9 RMS vs FileConnection API  FileConnection  familiar (simpler) to use  provides access to images, sounds, etc.  needs security privileges  may not be supported on older devices  RMS  available on all MIDP devices  does not require security privileges  may be more appropriate for some applications  more cumbersome to use

10 RecordStores  Mini databases that consist of a collection of records (byte arrays)  Could be shared across MIDlets

11 RecordStores  Mini databases that consist of a collection of records (byte arrays)  Could be shared across MIDlets  Creating Record Stores (via static methods) RecordStore openRecordStore(String name, boolean create) RecordStore openRecordStore(String name, boolean create, int auth, boolean writable) auth = AUTHMODE_ANY – accessible by all midlets AUTHMODE_PRIVATE – restricted to this midlet

12 RecordStores  Mini databases that consist of a collection of records (byte arrays)  Could be shared across MIDlets  Creating Record Stores (via static methods) RecordStore openRecordStore(String name, boolean create) RecordStore openRecordStore(String name, boolean create, int auth, boolean writable) auth = AUTHMODE_ANY – accessible by all midlets AUTHMODE_PRIVATE – restricted to this midlet  Manipulating Record Stores int addRecord(byte[] data, int offset, int numBytes) void deleteRecord(int recordID) byte[] getRecord(int recordID) void setRecord(int recordID, byte[] data, int offset, int numBytes) int getNumRecords() int getRecordSize(int recordID)

13 Writing to RecordStore void saveRecords(String rsName) { RecordStore rs = RecordStore.openRecordStore(rsName, true); String[] data = {“Mickey”, “Minnie”, “Donald”, “Tom”, “Jerry”}; for (int i = 0; i < data.length; ++i) { byte[] bytes = data[i].getBytes(); rs.addRecord(bytes, 0, bytes.length); } rs.closeRecordStore(); } // NOTE: The RecordStore methods throw exceptions – put try/catch.


Download ppt "Detecting Changes  ItemStateListener interface – detect changes in internal state of an Item  new selection made in a ChoiceGroup  adjusted value of."

Similar presentations


Ads by Google