| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1133 人关注过本帖
标题:swt desinger 的问题 怎么点击按钮切换界面 急 谢谢
只看楼主 加入收藏
fjhfjh
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-30
收藏
 问题点数:0 回复次数:0 
swt desinger 的问题 怎么点击按钮切换界面 急 谢谢
我用swt desinger 做一个界面 想用两个按钮控制不同的界面切换 可是不好使 不知道是什么原因 希望能得到帮助
代码如下:
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class dd {

    protected Shell shell;

    /**
     * Launch the application
     * @param args
     */
    public static void main(String[] args) {
        try {
            dd window = new dd();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Open the window
     */
    public void open() {
        final Display display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }

    /**
     * Create contents of the window
     */
    protected void createContents() {
        shell = new Shell();
        shell.setLayout(new FormLayout());
        shell.setSize(500, 375);
        shell.setText("SWT Application");

        final Composite composite = new Composite(shell, SWT.NONE);
        final StackLayout stackLayout = new StackLayout();
        composite.setLayout(stackLayout);
        final FormData fd_composite = new FormData();
        fd_composite.top = new FormAttachment(10, 0);
        fd_composite.left = new FormAttachment(0, 25);
        fd_composite.bottom = new FormAttachment(0, 335);
        fd_composite.right = new FormAttachment(0, 435);
        composite.setLayoutData(fd_composite);

    final    Composite composite_1;
        composite_1 = new Composite(composite, SWT.NONE);
        composite_1.setLayout(new StackLayout());
        composite_1.setBounds(10, 10, 300, 300);

final        Composite composite_2;
        composite_2 = new Composite(composite, SWT.NONE);
        final StackLayout stackLayout_1 = new StackLayout();
        composite_2.setLayout(stackLayout_1);
        composite_2.setBounds(10,10,250,250);

        final Label label;
        label = new Label(composite_2, SWT.NONE);
        label.setText("Label");
        stackLayout_1.topControl = label;
        stackLayout.topControl = composite_2;

        final Button button = new Button(shell, SWT.NONE);
        button.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(final SelectionEvent e) {
            stackLayout.topControl= composite_2;
            }
        });
        final FormData fd_button = new FormData();
        fd_button.top = new FormAttachment(0, 222);
        fd_button.bottom = new FormAttachment(0, 245);
        fd_button.left = new FormAttachment(0, 450);
        button.setLayoutData(fd_button);
        button.setText("button");

        final Button button_1 = new Button(shell, SWT.NONE);
        button_1.addMouseListener(new MouseAdapter() {
            public void mouseDown(final MouseEvent e) {
            }
        });
        button_1.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(final SelectionEvent e) {
                stackLayout_1.topControl=label;
                stackLayout.topControl=composite_1;
            }
        });
        final FormData fd_button_1 = new FormData();
        fd_button_1.top = new FormAttachment(0, 175);
        fd_button_1.left = new FormAttachment(button, 0, SWT.LEFT);
        button_1.setLayoutData(fd_button_1);
        button_1.setText("button");
        
        //
    }

}
搜索更多相关主题的帖子: desinger swt 按钮 界面 
2008-10-30 10:33
快速回复:swt desinger 的问题 怎么点击按钮切换界面 急 谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018844 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved