很简单,主要目的是用来测试刚刚摸索着搭建起来的Eclipse3.2+MyEclipse5.0.1GA+SWT Designer5.1.1环境.
算是自己这几天研究的一点点小进步吧.
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();
}
}
}

- 描述: 效果截图.
- 大小: 26.5 KB
分享到:
相关推荐
SWT Designer是一款强大的图形用户界面(GUI)设计工具,主要用于帮助Java开发者轻松创建基于Eclipse RCP(Rich Client Platform)和SWT(Standard Widget Toolkit)的应用程序。标题"swt-designer -features"暗示...
SWTDesigner是一个用于创建SWT界面的可视化编辑器,它作为Eclipse的一个插件存在。通过SWTDesigner,开发者可以使用拖拽的方式快速构建复杂的UI布局,大大提高了开发效率。此外,SWTDesigner还提供了实时预览功能,...
SWT,全称为Standard Widget Toolkit,是一个开源的GUI(图形用户界面)编程框架,主要用于Java应用程序。它由IBM开发,最初是为了改善Java的GUI开发体验,尤其是在解决AWT(Abstract Windowing Toolkit)存在的问题...
总体而言,SWT Designer V7.6是Java UI开发的重要工具,它简化了基于SWT和JFace的应用程序开发,让开发者能够更加专注于业务逻辑,而非繁琐的界面布局工作。对于任何希望提升Java桌面应用开发效率的团队或个人,这款...
- 除了VisualEditor外,还有其他工具可供选择,如SWTDesigner等,这些工具各有特点,可以根据实际需求选择使用。 通过以上内容的学习,开发者可以全面掌握Eclipse插件开发的基本原理和技术细节,为进一步深入研究...