package demotest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
/**
*
* @author mositure
*
*/
public class LinkSample {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//创建一个display对象
Display display = new Display();
//shell是程序的主窗体
Shell shell=new Shell(display);
//设置窗体大小
shell.setSize(400, 400);
//设置主窗体的标题
shell.setText("Link组件");
String msg = "<A href=\"www.baidu.com\">超链接</A>";
Link link = new Link(shell, SWT.NONE);
link.setText(msg);
link.setSize(200, 60);
//注册点击超链接事件
link.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
System.out.println("打开连接");
}
});
//打开主窗体
shell.open();
//如果主窗体没有关闭
while(!shell.isDisposed()){
//如果display不忙
if(!display.readAndDispatch()){
//休眠
display.sleep();
}
}
//销毁display
display.dispose();
}
}