2010年6月13日

Eclipse Nebula Project: RadioGroup

Nebula Projec
//-- Main.java --
import org.eclipse.nebula.widgets.radiogroup.RadioGroup;
import org.eclipse.nebula.widgets.radiogroup.RadioItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class Main {

public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("RadioGroup");
shell.setLayout(new FillLayout());

final RadioGroup rg = new RadioGroup(shell, SWT.NONE);
(new RadioItem(rg, 0)).setText("Red");
(new RadioItem(rg, 0)).setText("Green");

Listener listener = new Listener() {

@Override
public void handleEvent(Event arg) {
if (arg.item != null) {
System.out.println("index: " + arg.index + " text: "
+ ((RadioItem) arg.item).getText());
}
}

};
rg.addListener(SWT.Selection, listener);
shell.pack();
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

沒有留言:

網誌存檔