Java Reference
In-Depth Information
Listing 17-2. The WeatherWidget Class Using the Location API
package com.apress.rischpater.weatherwidget;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
public class WeatherWidget extends MIDlet
implements CommandListener, Runnable {
private Form wxForm;
private Alert locatingAlert;
private StringItem wxItem;
private Command exitCommand;
private Command screenCommand;
private Command settingCommand;
private Command okCommand;
private Command backCommand;
private Command locateCommand;
private List locationList;
private TextBox locationTextBox;
private Alert cannotAddLocationAlert;
private WeatherFetcher fetcher;
private WeatherLocation wxlocation;
private WeatherLocationStore locationStore;
private void initialize() {
locationStore = new WeatherLocationStore();
String[] locations = locationStore.getLocationStrings();
try {
if (locations.length>0)
wxlocation = locationStore.getLocation(locations[0]);
}
catch(Exception e){}
fetcher = new WeatherFetcher(wxlocation, this);
getDisplay().setCurrent(get_wxForm());
}
public void startApp() {
initialize();
}
 
Search WWH ::




Custom Search