import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class aaa extends Shell {

public static void main(String args[]) {
try {
Display display = Display.getDefault();
aaa shell = new aaa(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public aaa(Display display, int style) {
super(display, style);
createContents();
} protected void createContents() {
setText("SWT Application");
setSize(500, 375);

final Button button = new Button(this, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
aaa a = new aaa(e.display,swt.no)
                                     a.opem();
}
});
button.setText("button");
button.setBounds(173, 152, 48, 22);
//
} @Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}}
我每点击按钮的同时》只要窗口打开了.在点按钮就不想在打开新的窗口了,除非新窗口关闭.然后在点击按钮才能在打开新的窗口

解决方案 »

  1.   


    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.MouseAdapter;
    import org.eclipse.swt.events.MouseEvent;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    public class Test extends Shell {

    private static Shell shell;

    public static Object openSingle(){
    if(shell==null || shell.isDisposed()){
    shell = new Shell(new Shell().getDisplay(),SWT.SHELL_TRIM);
    }
    shell.open();
    return null;
    } public static void main(String args[]) {
    try {
    Display display = Display.getDefault();
    Test shell = new Test(display, SWT.SHELL_TRIM);
    shell.open();
    shell.layout();
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
    display.sleep();
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    public Test(Display display, int style) {
    super(display, style);
    createContents();
    }

    protected void createContents() {
    setText("SWT Application");
    setSize(500, 375); final Button button = new Button(this, SWT.NONE);
    button.setText("button");
    button.setBounds(283, 232, 48, 22);
    button.addMouseListener(new MouseAdapter(){
    public void mouseUp(MouseEvent arg0) {
    // TODO Auto-generated method stub
    Test.openSingle();
    }});
    //
    } @Override
    protected void checkSubclass() {
    }
    }