Steps to follow to create a MIDlet that dipsplays Help Message
- Declare references.
- Obtain a reference to the instance of the Display class.
- Create an instance of the Command class to return from the help page.
- Create an instance of the Command class to exit the MIDlet.
- Create an instance of the Form class.
- Create an instance of the TextBox class that contains the help text.
- Associate the instance of the Back Command class with the instance of the TextBox class.
- Associate the instance of the Exit Command class and the instance of the Help Command class with the instance of the Form class.
- Associate a CommandListener with the instance of the Form class.
- Associate a CommandListener with the instance of the TextBox class.
- Display the form.
- Evaluate the command that the user entered into the small computing device.
- If the command is the Back command, display the form.
- If the command is the Exit command, terminate the MIDlet.
- If the command is the Help command, display the text box.
ShowHelpMidlet.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ShowHelpMidlet extends MIDlet implements CommandListener
{
private Display display;
private Command back;
private Command exit;
private Command help;
private Form form;
private TextBox helpMesg;
public ShowHelpMidlet()
{
display = Display.getDisplay(this);
back = new Command("Back", Command.BACK, 2);
exit = new Command("Exit", Command.EXIT, 1);
help = new Command("Help", Command.HELP, 3);
form = new Form("Online Help Example");
helpMesg = new TextBox("Online Help", "Press Back to return to the previous screen or press Exit to close this program.",
81, 0);
helpMesg.addCommand(back);
form.addCommand(exit);
form.addCommand(help);
form.setCommandListener(this);
helpMesg.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{ }
public void destroyApp(boolean unconditional)
{ }
public void commandAction(Command command, Displayable displayable)
{
if (command == back)
{
display.setCurrent(form);
}
else if (command == exit)
{
destroyApp(false);
notifyDestroyed();
}
else if (command == help)
{
display.setCurrent(helpMesg);
}
}
}
Output Screens: