窗体1publicclassaextendsShell{staticDisplaydisplay;staticashell;publicstaticvoidmain(Stringargs[]){try{display=Display.getDefault();shell=newa(display,SWT.SHELL_TRIM);she...
窗体1
public class a extends Shell {
static Display display;
static a shell;
public static void main(String args[]) {
try {
display= Display.getDefault();
shell = new a(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public a(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) {
b b=new b(display,SWT.CLOSE);
b.open();
shell.setVisible(false);
}
});
button.setText("button");
button.setBounds(210, 168, 48, 25);
//
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
窗体2:为窗体添加关闭事件
addShellListener(new ShellAdapter() {
public void shellClosed(final ShellEvent e) {
a a=new a(b.display,SWT.CLOSE);
a.setVisible(true);
}
});
为什么第一次打开窗体一点按钮会打开窗体二 关闭窗体2也会将窗体1显示出来 可是再次点击按钮 窗体一却不隐藏了 而且关闭窗体2有新打开个窗体1
展开