Let's start adding functionality to the application. First, add the Exit softkey command:
... 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); }
Again, 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, that
is, the right softkey (RSK). Forms also have a default command (set
using 'setDefaultCommand') that gets assigned to the middle softkey
(MSK). Other commands are assigned to the Options menu.
When run, the application output looks like this: