Being notified when other shell is being closed [message #554393] |
Sun, 22 August 2010 19:19 |
larsk Messages: 22 Registered: October 2009 Location: Sweden |
Junior Member |
|
|
I have written a test application where I want to know when the second shell is being closed.
The application starts with MainShell from where I can open SecondShell. Is there any way that I from MainShell can be notified when SecondShell is being closed?
Code from the file MainShell.java:
package swtshelltest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
public class MainShell extends Shell
{
Button buttonOpen = new Button(this, SWT.NONE);
public static void main(String[] args)
{
MainShell main = new MainShell();
}
MainShell()
{
super(Display.getDefault(), SWT.CLOSE);
this.setText("MainShell");
this.setBounds(100, 100, 200, 200);
buttonOpen.setText("Open");
buttonOpen.setLocation(10, 10);
buttonOpen.pack();
buttonOpen.addSelectionListener(openSecondShell);
this.open();
while (!this.isDisposed())
{
if (!Display.getDefault().readAndDispatch())
Display.getDefault().sleep();
}
}
@Override
protected void checkSubclass()
{
}
//funktion som körs när man klickar på knappen som startar resultatvisningen
SelectionListener openSecondShell = new SelectionListener()
{
@Override
public void widgetSelected(SelectionEvent event)
{
SecondShell secondShell = new SecondShell();
}
@Override
public void widgetDefaultSelected(SelectionEvent event)
{
}
};
}
Code from the file SecondShell.java:
package swtshelltest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SecondShell extends Shell
{
SecondShell()
{
super(Display.getDefault(), SWT.CLOSE);
this.setText("SecondShell");
this.setBounds(400, 100, 100, 100);
this.open();
}
@Override
protected void checkSubclass()
{
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03590 seconds