编程语言

img happy1123

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

发表于2004/10/10 11:20:00  1224人阅读

这个程序用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

相关文章推荐

img
取 消
img