![](http1://img.it610.com/image/info5/875d519f8f94492d826532b5af0c89b1.jpg)
算是自己这几天研究的一点点小进步吧.
package com.javaeye.leon; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; import com.swtdesigner.SWTResourceManager; public class SwiftOffice { // 声明了程序中需要用到的4个控件类 private static Group group; private static Combo combo; private static Button button_set; private static Button button_get; public static void main(String[] args) { final Display display = Display.getDefault(); final Shell shell = new Shell(); shell.setImage(SWTResourceManager.getImage(SwiftOffice.class, "/image/star1.gif")); shell.setSize(500, 375); shell.setText("SWT Application"); shell.open(); group = new Group(shell, SWT.NONE); group.setText("A组"); group.setBounds(29, 21, 170, 123); button_set = new Button(group, SWT.NONE); button_set.setText("设值"); button_set.setBounds(58, 88, 44, 23); // 外部类MyWidgetSelected实现事件响应 final class MyWidgetSelected extends SelectionAdapter { public void widgetSelected(SelectionEvent e) { combo.removeAll(); for (int i = 1; i <= 10; i++) combo.add("第" + i + "个字符串"); combo.select(0); } } button_set.addSelectionListener(new MyWidgetSelected()); button_get = new Button(group, SWT.NONE); button_get.setBounds(108, 88, 44, 23); button_get.setText("取值"); // 匿名内部类实现事件响应 button_get.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { MessageDialog.openInformation(shell, null, combo.getText()); } }); combo = new Combo(group, SWT.NONE); combo.setBounds(23, 45, 129, 21); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }