基于SWT-Designer建立的一个小程序.

本文介绍了一个使用Eclipse3.2+MyEclipse5.0.1GA+SWTDesigner5.1.1环境构建的简单SWT应用程序示例。该程序通过按钮设置和获取组合框中的字符串值,演示了基本的GUI元素及其交互方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

很简单,主要目的是用来测试刚刚摸索着搭建起来的Eclipse3.2+MyEclipse5.0.1GA+SWT Designer5.1.1环境. :shock:

算是自己这几天研究的一点点小进步吧.

[code]
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();
}
}
}
[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值