package org; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MB2 { protected MB2(Shell shell) { shell.setLayout(new GridLayout()); Button clickMe = new Button(shell, SWT.PUSH); clickMe.setText("Click Me"); clickMe.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false)); clickMe.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { MessageBox dialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO); dialog.setText(shell.getText()); dialog.setMessage("Yes or no?"); dialog.open(); } }); } public static void main(String[] args) { System.out.println(SWT.getVersion()); Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Test"); MB2 ui = new MB2(shell); ui.toString(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }