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");
//
}
}