Search This Blog

Wednesday, 16 August 2023

Creating a MIDlet Using Command Object for Displaying Help Message

0 comments

Steps to follow to create a MIDlet that dipsplays Help Message 

  1. Declare references. 
  2. Obtain a reference to the instance of the Display class. 
  3. Create an instance of the Command class to return from the help page. 
  4. Create an instance of the Command class to exit the MIDlet. 
  5. Create an instance of the Form class. 
  6. Create an instance of the TextBox class that contains the help text. 
  7. Associate the instance of the Back Command class with the instance of the TextBox class. 
  8. Associate the instance of the Exit Command class and the instance of the Help Command class with the instance of the Form class. 
  9. Associate a CommandListener with the instance of the Form class. 
  10. Associate a CommandListener with the instance of the TextBox class. 
  11. Display the form. 
  12. Evaluate the command that the user entered into the small computing device. 
  13. If the command is the Back command, display the form. 
  14. If the command is the Exit command, terminate the MIDlet. 
  15. 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:





Leave a Reply