Adding Command Buttons
Description:
The following code shows how to add Command Buttons to a MIDlet.
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class Command_ex extends MIDlet implements CommandListener
{
Display display=Display.getDisplay(this);
Command ExitCmd = new Command ("Exit",Command.EXIT,7);
Command CheckCmd = new Command ("Check",Command.SCREEN,1);
public void startApp()
{
Form form = new Form("Commands example");
form.append("This is a Command button example. Please press the Check button ");
form.addCommand(ExitCmd);
form.addCommand(CheckCmd);
form.setCommandListener(this);
display.setCurrent(form);
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
..........
public void commandAction(Command c, Displayable d)
{
if (c==ExitCmd)
{
destroyApp(true);
}
else if (c==CheckCmd)
{
Alert alert = new Alert("Alert");
alert.setString("Check button test");
alert.setTimeout(3000); // 3 seconds
display.setCurrent(alert, display.getCurrent() );
}
}
}


