Java by API/org.eclipse.swt.events/DisposeListener

Материал из Java эксперт
Перейти к: навигация, поиск

implements DisposeListener

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   // Create the main window
   Shell mainShell = new Shell(display);
   final Shell childShell = new Shell(mainShell);
   childShell.addDisposeListener(new DisposeListener() {
     public void widgetDisposed(DisposeEvent event) {
       System.out.println("Gotcha");
     }
   });
   childShell.setLayout(new FillLayout());
   childShell.setText("little brother");
   Button button = new Button(childShell, SWT.PUSH);
   button.setText("Close Me!");
   button.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent event) {
       childShell.close();
     }
   });
   childShell.open();
   while (!mainShell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}

      </source>