This screen is used to create a new message entry to the record store. It contains fields for the message and the password.
To create the class:
Assign the
class to the package satsa
and import the required classes.
package satsa; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.TextField;
Create the
class by extending Form
and implementing CommandListener
.
// Displays a form to enter new messages class NewScreen extends Form implements CommandListener { private final SATSAMIDlet midlet; private final Command commandBack = new Command("Back", Command.BACK, 1); private final Command commandSave = new Command("Save", Command.ITEM, 1); TextField messageField; TextField passwordField; NewScreen(SATSAMIDlet midlet) { super(null); this.midlet = midlet; } public void commandAction(Command c, Displayable d) { if (c==commandBack) { midlet.showMessageList(); } if (c==commandSave) { midlet.addNewMessage(messageField.getString(), passwordField.getString()); } } void createForm() { deleteAll(); setTitle("Add new message "); messageField = new TextField("Message", "", 80, TextField.ANY); // Notice that the max length is 16 as indicated for the AES key passwordField = new TextField("Password", "", 16, TextField.PASSWORD); append(messageField); append(passwordField); addCommand(commandBack); addCommand(commandSave); setCommandListener(this); } }