SWT学习笔记(3)——第一个程序

这个程序用VE插件自动生成,VE的信息见http://blog.csdn.net/happy1123/archive/2004/10/10/130395.aspx

源码:

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class SwtAppTest {

     private Shell sShell = null;//Shell相当于一个Form,用于放置其他组件

     private Button button = null;
     private Label label = null;
     public static void main(String[] args) {
          /* Before this is run, be sure to set up the following in the launch configuration
           * (Arguments->VM Arguments) for the correct SWT library path.
           * The following is a windows example:
           * -Djava.library.path="installation_directory/plugins/org.eclipse.swt.win32_3.0.0/os/win32/x86"
           */
          Display display = Display.getDefault();  //Display负责与底层操作系统连接
          SwtAppTest thisClass = new SwtAppTest();
          thisClass.createSShell() ;
          thisClass.sShell.open();
  
          while (!thisClass.sShell.isDisposed()) {//循环等待请求
               if (!display.readAndDispatch()) display.sleep ();//如果没有请示则处于Sleep状态
          }
          display.dispose();  //千万别忘了把display dispose掉
     }

 /**
  * This method initializes sShell
  */
    private void createSShell() {
         sShell = new Shell();  
         button = new Button(sShell, SWT.NONE);
         label = new Label(sShell, SWT.NONE);
         sShell.setSize(new Point(300,200));
         sShell.setText("Shell");
         button.setBounds(new org.eclipse.swt.graphics.Rectangle(116,116,72,22));
         button.setText("Exit");
         label.setText("Hello World!");
         label.setBounds(new Rectangle(117,50, 72, 12));
         button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
             public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {   
                 System.exit(0);
            }
         });
    }
}

这是一个Hello World.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值