public class ButtonShell {
private Display display;
private Shell shell;
ButtonShell() {
display = new Display();
shell = new Shell(display);
shell.setText("Just 2 Buttons");
createButton();
shell.pack();
shell.open();
while (!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();
}
private void createButton() {
GridLayout layout = new GridLayout();
layout.numColumns = 1;
shell.setLayout(layout);
Button button1 = new Button(shell, SWT.NONE);
button1.setText("Button No 1");
button1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.setText("Button 1: click");
}
});
Button button2 = new Button(shell, SWT.NONE);
button2.setText("Button No 2");
button2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.setText("Button 2: click");
}
});
}
public static void main(String[] args) {
new ButtonShell();
}
}