import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Snippet1 {
public static void main (String[]args) {
Display display = new Display(); //화면 생성
Shell shell = new Shell(display); //쉘 생성
Button ok = new Button(shell, SWT.PUSH);
ok.setText("클릭1");
Button ok2 = new Button(shell, SWT.PUSH);
ok2.setText("클릭2");
SelectionAdapter selectionAdapter = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("버튼1 클릭 되었음!");
}
};
ok.addSelectionListener(selectionAdapter);
ok2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("버튼2 클릭 되었음!");
}
});
shell.setLayout(new RowLayout());
shell.pack(); //실제로 나올 화면(쉘)을 최적화.
shell.open(); //쉘을 띄운다.
//종료를 실행하지 않은 상태라면 화면을 계속 띄어줌
while (!shell.isDisposed()) {
//display.asyncExec(); //쓰레드관련 작업
//사용하지 않을시 리소르를 차지 하지 않음.
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
[출처] JAVA SWT 간단한 예제|작성자 pennyyb