import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class SWTHelloWorld { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Hallo Welt"); shell.setLayout(new FillLayout(SWT.VERTICAL)); Text text = new Text(shell, SWT.NONE); text.setText("Welt"); Label label = new Label(shell, SWT.NONE); label.setText("Hallo " + text.getText()); Button button = new Button(shell, SWT.PUSH); button.setText("Klick"); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { label.setText("Hallo " + text.getText()); } }); shell.setSize(150, 150); Monitor mon = display.getPrimaryMonitor(); Rectangle mRect = mon.getBounds(); int x = (mRect.width - 150) / 2; int y = (mRect.height - 150) / 2; shell.setLocation(x, y); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }