/* * RecordMIDlet.java * * Created on 13 ??????? 2546, 16:38 ?. */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * An example MIDlet with simple "Hello" text and an Exit command. * Refer to the startApp, pauseApp, and destroyApp * methods so see how each handles the requested transition. * * @author sup98 * @version */ public class RecordMIDlet extends MIDlet{ private Preferences mPreferences; private Form mForm; private TextField mUserField, mPasswordField; public void startApp() { //Try to load the user and password from a recordstore mPreferences = Preferences.getInstance(); if(mForm == null){ mForm = new Form("Login"); mUserField = new TextField("Name", mPreferences.getUser(), 32, 0); mPasswordField = new TextField("Password", mPreferences.getPassword(), 32, TextField.PASSWORD); mForm.append(mUserField); mForm.append(mPasswordField); mForm.addCommand(new Command("Exit", Command.EXIT, 0)); mForm.setCommandListener(new CommandListener(){ public void commandAction(Command c,Displayable s){ if(c.getCommandType() == Command.EXIT){ destroyApp(true); notifyDestroyed(); } } } ); } Display.getDisplay(this).setCurrent(mForm); } /** * Pause is a no-op since there are no background activities or * record stores that need to be closed. */ public void pauseApp() { } /** * Destroy must cleanup everything not handled by the garbage collector. * In this case there is nothing to cleanup. */ public void destroyApp(boolean unconditional) { //Save the user name and password mPreferences.setUser(mUserField.getString()); mPreferences.setPassword(mPasswordField.getString()); mPreferences.store(); } }