Java Reference
In-Depth Information
The first case is trivial and uses the store instance's setRecord method to update the
existing record. The second case is a little more involved and requires that you search
the database to get the record ID of the existing record. You do this using the existing
getLocation method and copying over the data to update from the original Location
instance. Finally, the third case is also trivial: it just calls out to addLocation directly.
Integrating the Location and LocationStore classes into the WeatherWidget MIDlet is
straightforward. Listing 6-7 shows the results.
Listing 6-7. The Revised WeatherWidget Example Incorporating the Location and
LocationStore Classes
package com.apress.rischpater.weatherwidget;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class WeatherWidget extends MIDlet implements CommandListener {
private Form wxForm;
private StringItem locationItem;
private StringItem wxItem;
private Command exitCommand;
private Command screenCommand;
private Command settingCommand;
private Command okCommand;
private Command backCommand;
private List locationList;
private TextBox locationTextBox;
private Alert cannotAddLocationAlert;
String location;
LocationStore locationStore;
/** This method initializes the UI of the application.
*/
private void initialize() {
locationStore = new LocationStore();
String[] locations = locationStore.getLocationStrings();
if (locations.length>0)location = locations[0];
getDisplay().setCurrent(get_wxForm());
}
 
Search WWH ::




Custom Search