Add Exit command, to close the MIDlet. at the end of startApp().
To create a new Command instance and close the MIDlet, use the following code:
... import com.sun.lwuit.events.ActionEvent; public void startApp() { Display.init(this); Form form = new Form("Hello World"); form.show(); //add exit command Command exitCommand = new Command("Exit") { public void actionPerformed(ActionEvent e) { notifyDestroyed(); } }; form.addCommand(exitCommand); form.setBackCommand(exitCommand); }
The Command class is analogous to the LCDUI class with the same name. By default, LWUIT uses a full-screen canvas and draws its own softkey area. Setting the Command as the Form's back command ensures that it is displayed in the correct place i.e. the default single back key. Other commands are assigned to the Options menu.