Tuesday, August 5, 2008

Use of RadioButton / ChoiceGroup in J2ME application

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class RadioButtonTest extends MIDlet implements CommandListener {
private Display display;
private Form form;
private Command exitCommand;
private ChoiceGroup movies;
private Command process;

public void startApp() {
display = Display.getDisplay(this);

form = new Form("");
movies = new ChoiceGroup("Select Movies You Like to See", Choice.EXCLUSIVE);
movies.append("A", null);
movies.append("B", null);
form.append(movies);
process = new Command("Process", Command.SCREEN, 2);
exitCommand = new Command("Exit", Command.EXIT, 0);
form.addCommand(exitCommand);
form.addCommand(process);
form.setCommandListener(this);
display.setCurrent(form);
}

protected void pauseApp() {
}

protected void destroyApp(boolean arg0) {
}

public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();
} else if (c == process) {
form.append(new StringItem("", movies.getSelectedIndex()==0?"true":"false" ));
}
}
}

No comments:

search engine

Custom Search