SWT第一个程序测试

首先需要下载SWT插件,下载后建立SWT工程。
import org.eclipse.swt.*;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.*;


public class HelloSwt extends Shell {
private static Text text;
private static Button swtButton;
private static Button swingButton;
private static Button awtButton;
private static Group group;
private static Button button;
private static Label benefitOfSwtLabel;
private static List list;

public static void main(String[] args) {
// TODO Auto-generated method stub

Display display=Display.getDefault();
final Shell shell=new Shell(display);
shell.setText("Hello Swt");
shell.setSize(260, 283);
shell.open();
//创建一个文本框
text=new Text(shell,SWT.BORDER);
text.setText("swt是图形工具箱");
text.setBounds(10,8,230,35);
//创建标签标注
benefitOfSwtLabel=new Label(shell,SWT.None);
benefitOfSwtLabel.setText("swt 的优点");
benefitOfSwtLabel.setBounds(10,49,90,15);
//创建一个列表
list=new List(shell,SWT.BORDER);
list.setItems(new String[]
{
"使用操作系统本地控件",
"提供一套平台无关的API",
"gui程序的运行速度快",
"更多。。。"
}
);
list.setBounds(10,68,232,82);
//group
group=new Group(shell,SWT.None);
group.setText("你使用过那些图形工具箱?");
group.setBounds(10,159,230,47);
//在group里放置多选框
awtButton=new Button(group,SWT.CHECK);
awtButton.setText("AWT");
awtButton.setBounds(10,20,54,18);
swingButton=new Button(group, SWT.CHECK);
swingButton.setText("swing");
swingButton.setBounds(70, 22, 60, 15);
swtButton=new Button(group, SWT.CHECK);
swtButton.setText("swt");
swtButton.setBounds(136, 22, 62, 15);
//事件监听按钮
button=new Button(shell, SWT.None);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e)
{
MessageBox msgbox=new MessageBox(shell, SWT.ICON_INFORMATION);
msgbox.setMessage("Hello SWT!");
msgbox.open();
}
});
button.setText("按下按钮,说hello");
button.setBounds(10,214,227,25);
//shell.layout();
//界面停住
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值