Java Reference
In-Depth Information
The run() method contains the code to write the HashTable to the file system. The mSaving
flag is used to ensure that the user will not exit the application while an I/O thread is still saving
data to the file system.
The GUI MIDlet that uses the FileBasedPreferences class is called FCMIDlet , which is shown
in Listing 9-2. The user interface is identical to the one in RecordMIDlet from Chapter 8.
Listing 9-2. Source Code of the FCMIDlet
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStoreException;
import java.io.*;
public class FCMIDlet
extends MIDlet
implements CommandListener {
private static final String kUser = "user";
private static final String kPassword = "password";
private FileBasedPreferences mPreferences;
private Form mForm;
private TextField mUserField, mPasswordField;
private Command mExitCommand, mSaveCommand;
public FCMIDlet() {
try {
verifyFileConnectionSupport();
mPreferences = new FileBasedPreferences("preferences");
}
catch (IOException 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("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);
mExitCommand =new Command("Exit", Command.EXIT, 0);
mSaveCommand = new Command("Save", "Save Password", Command.SCREEN, 0);
mForm.addCommand(mExitCommand);
Search WWH ::




Custom Search