packagedev.equo;importorg.eclipse.swt.SWT;importorg.eclipse.swt.layout.FillLayout;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Label;importorg.eclipse.swt.widgets.Shell;/** * Exercises the Shell close contract: the first close gesture is vetoed with {@code doit = false} * and must leave the window standing; the second is accepted and must dispose the shell and let the * process exit. Drive it with the title-bar X (or Alt+F4) and read the printed trace. */publicclassShellCloseVetoSnippet{publicstaticvoidmain(String[]args){Displaydisplay=newDisplay();Shellshell=newShell(display);shell.setText("Close me twice");shell.setLayout(newFillLayout());shell.setSize(420,160);Labellabel=newLabel(shell,SWT.CENTER|SWT.WRAP);label.setText("First close is vetoed, second one closes.");boolean[]allow={false};shell.addListener(SWT.Close,e->{e.doit=allow[0];System.out.println("TRACE SWT.Close doit="+e.doit);allow[0]=true;});shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch())display.sleep();}display.dispose();System.out.println("TRACE exited");}}