Java Reference
In-Depth Information
Working with the PIM API
Putting the API to use, the first MIDlet will write contact information to the PIM database.
SeedMIDlet , shown in Listing 9-3, writes four contact records into the PIM database using the
PIM optional APIs.
Listing 9-3. Source Code for a MIDlet to Seed the PIM Database with Contacts
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.pim.*;
public class SeedMIDlet
extends MIDlet implements CommandListener {
private Form mForm;
private Command mExitCommand;
public SeedMIDlet() {
try {
verifyPIMSupport();
seed();
}
catch (Exception ex) {
mForm = new Form("Exception");
mForm.append(new StringItem(null, ex.toString()));
mExitCommand = new Command("Exit", Command.EXIT, 0);
mForm.addCommand(mExitCommand);
mForm.setCommandListener(this);
return;
}
mForm = new Form("Data Seeded");
mForm.append(new StringItem(null, "PIM data stored."));
mExitCommand = new Command("Exit", Command.EXIT, 0);
mForm.addCommand(mExitCommand);
mForm.setCommandListener(this);
}
public void startApp() {
Display.getDisplay(this).setCurrent(mForm);
}
public void pauseApp() {}
Search WWH ::




Custom Search