Friday, July 16, 2010

LWUIT: ButtonGroup

The ButtonGroup component manages the selected and unselected states for a set of
RadioButtons. For the group, the ButtonGroup instance guarantees that only one
button can be selected at a time.

LWUIT: ButtonGroup


import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import com.sun.lwuit.layouts.BorderLayout;

public class LwuitButtonGroup extends MIDlet implements ActionListener {
public void startApp() {
Display.init(this);
Form f = new Form("Hello, MIDlet in LWUIT!");
Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.setCommandListener(this);

f.setTitle("ButtonGroup");

RadioButton radioButton1 = new RadioButton("Radio Button 1");
RadioButton radioButton2 = new RadioButton("Radio Button 2");
RadioButton radioButton3 = new RadioButton("Radio Button 3");
ButtonGroup buttonGroup1 = new ButtonGroup();
buttonGroup1.add(radioButton1);
buttonGroup1.add(radioButton2);
buttonGroup1.add(radioButton3);
f.addComponent(radioButton1);
f.addComponent(radioButton2);
f.addComponent(radioButton3);

RadioButton radioButtonA = new RadioButton("Radio Button A");
RadioButton radioButtonB = new RadioButton("Radio Button B");
ButtonGroup buttonGroup2 = new ButtonGroup();
buttonGroup2.add(radioButtonA);
buttonGroup2.add(radioButtonB);
f.addComponent(radioButtonA);
f.addComponent(radioButtonB);

f.show();

}

public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}