Java Reference
In-Depth Information
and password from the RecordStore instead of requiring the user to enter the same information
over and over.
The MIDlet itself is very simple. Its only screen is a Form that contains fields for entering the
user name and password. It uses a helper class, Preferences , to do all the RecordStore work.
Listing 8-1 shows the source code for the MIDlet.
Listing 8-1. Source Code for RecordMIDlet
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStoreException;
public class RecordMIDlet
extends MIDlet
implements CommandListener {
private static final String kUser = "user";
private static final String kPassword = "password";
private Preferences mPreferences;
private Form mForm;
private TextField mUserField, mPasswordField;
public RecordMIDlet() {
try {
mPreferences = new Preferences("preferences");
}
catch (RecordStoreException rse) {
mForm = new Form("Exception");
mForm.append(new StringItem(null, rse.toString()));
mForm.addCommand(new Command("Exit", Command.EXIT, 0));
mForm.setCommandListener(this);
return;
}
mForm = new Form("Login");
mUserField = new TextField("Name",
mPreferences.get(kUser), 32, 0);
mPasswordField = new TextField("Password",
mPreferences.get(kPassword), 32, 0);
mForm.append(mUserField);
mForm.append(mPasswordField);
mForm.addCommand(new Command("Exit", Command.EXIT, 0));
mForm.setCommandListener(this);
}
Search WWH ::




Custom Search