JR 精品文章 - SWT初试
AD: jr (at) javaresearch.org


首页 | 动态 | 文章 | FAQ  | 新闻 | 下载 | 代码 | 工作 | 调查 | 术语 | 站点 | 图书 | 论坛 | 帮助 | 全部  

TOP | 交流 | 软件 | 专栏 | 开源 | 译/著 | 源码 | API  | 推荐 | FTP  | 积分 | 统计 | 搜索 | Blog | 我们  
首页 » 研究文集 » Java GUI 搜索标题相关文章 搜索标题相关文章    评论此文章 发表评论     开始监控此文章 开始监控   加入收藏夹  加入收藏夹
SWT初试
Terrile 原创   更新:2007-10-27 09:03:17  版本: 1.0   

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 放到主工程目录下

版权声明   给作者写信
本篇文章对您是否有帮助?  投票:         投票结果:     9       0
作者其它文章:
作者全部文章

这个文章共有 0 条评论
主题: 使用AWT可将Graphics对象转换为Image对象 上一篇文章
返回文章列表 返回〔Java GUI〕
下一篇文章 主题: 用java编写的一个钟


文字广告链接
        自主、快速定制基于JAVA的B/S业务系统          重量级企业在线自定义WEB报表平台
        Excel制表、零代码发布、打印、图表结合——快逸报表,免费、稳定、功能强大的java工具
        技术圈: 关于Java、dotNet、PHP、Ruby、奇客、Web2.0等更多资讯博客精选文章

关于 JR  |  版权声明  |  联系我们 

©2002-2006 JR 版权所有 沪ICP备05019622号