原文地址:http://www.cnblogs.com/liuzhuo/archive/2010/09/01/eclipse_plugin_1_3_1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public static void main(String[] args) {
// 生成Display的对象①
Display display = new Display();
// 生成Shell的对象②
final Shell shell = new Shell(display);
shell.setText("SWT的例子");
shell.setLayout(new FillLayout(SWT.VERTICAL));
// 生成Label对象③
Label label = new Label(shell, SWT.BORDER);
label.setText("请点按钮");
// 生成Button对象③
final Button button = new Button(shell, SWT.PUSH);
button.setText("OK");
// 为Button的时间定义监听器④
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
MessageBox messageBox = new MessageBox(shell, SWT.OK
| SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
messageBox.setMessage("按下了(" + button.getText() + ")按钮");
messageBox.open();
}
});
//打开shell对象 ⑤
shell.pack();
shell.open();
//结束前一直循环 ⑥
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
//释放display对象⑦
display.dispose();
}