Example code below adds an EXIT button on the MIDlet form along with the action listener.
Java Code:
private Display display;
private Form form = new Form("My form");
private Command exit = new Command("Exit", Command.EXIT, 1);
...
  public void startApp() {
  display = Display.getDisplay(this);
  form.addCommand(exit);  
  form.setCommandListener(this);  
  display.setCurrent(form);
 }
...
public void commandAction(Command command, Displayable displayable) {
if (command == exit) {
      destroyApp(false);
      notifyDestroyed();
    }
}