到 Google 资讯主页   
EasyJF首页   资料   源码   软件    论坛   网站    
   使用帮助    
    该信息为本站MyRSS系统缓存内容,部分图片及附件有可能无法正常使用.easyjf.comwww.javaresearch.org无关,不对该信息负责.通过http://www.javaresearch.org/article/77284.htm访问该信息的原始内容.
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   
SWT初试
作者: 来源:www.javaresearch.org  发布时间:2007-12-11 11:11:02.007


import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class StackLayoutSample {

  Display display = new Display();
  Shell shell = new Shell(display);
  
  final Button[] buttons = new Button[3];

  public StackLayoutSample() {
    final StackLayout stackLayout = new StackLayout();
    shell.setLayout(stackLayout);
    

    
    for(int i=0; i<buttons.length; i++) {
      buttons[i] = new Button(shell, SWT.NULL);
      buttons[i].setText("Button #" + i);
      
      buttons[i].addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
          // Flip to next button. 
          Button nextButton = null;
          for(int i=0; i<buttons.length; i++) {
            if(buttons[i] == e.widget) {
              if(i == buttons.length - 1) 
                nextButton = buttons[0];
              else
                nextButton = buttons[i+1];
            }
          }
          stackLayout.topControl = nextButton;
          shell.layout();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
      });
    }
    
    // Initial
    stackLayout.topControl = buttons[0];

    shell.setSize(200, 100);
    shell.open();

    // Set up the event loop.
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        // If no more entries in event queue
        display.sleep();
      }
    }

    display.dispose();
  }

  private void init() {

  }

  public static void main(String[] args) {
    new StackLayoutSample();
  }

}
说明:用Eclipse调试时,把mum.gif,rank.gif 放到主工程目录下

 
相关文章
 
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   


EasyJF.com 2006 隐私政策 使用EasyJF前必读