public class SimpleUI {
  
  	private static Shell shell;
  
  	private static String labelPrefix = "Number of button clicks: ";
  	private static int numOfClicks = 0;
  	private static Label label;
	
	public static void main(String[] args) {
		SimpleUI demo   = new SimpleUI(); 
		demo.open();
		demo.run();
		demo.close();
	}	
	
		
	void open() {
		shell = createShell();
		createShellContents(shell);
		shell.open();	
	}	
	
	
  	Shell createShell() {  		
		shell = new Shell();    	
		// Set window title 
		shell.setText("Simple UI Application");
    		// Set initial Size
    		shell.setSize(240,100); 
		// Create the layout
		FillLayout layout = new FillLayout();
		layout.type       = SWT.VERTICAL;		  		
		// Set layout into the composite 
		shell.setLayout(layout); 
		
		return shell;	   
  	}
  
  
    	static Shell getShell() {
    	
    		return shell; 
    }
    
  
  	void createShellContents(Shell parent) { 	
    		// Create widgets and add them to the composite
		Button   button   = new Button(getShell(), SWT.CENTER);
		label    = new Label(getShell(),SWT.CENTER);				
		// Set properties of widgets	
		button.setText("I'm a simple SWT button!");	
		label.setText(labelPrefix + numOfClicks);			
		// Handle the button click  
		button.addSelectionListener(new SelectionAdapter()  {
			public void widgetSelected (SelectionEvent e) {
				numOfClicks ++;
				label.setText(labelPrefix + numOfClicks);		
			} 
	    }); 
  	}		


	void run() {
		Display display = getShell().getDisplay();
	  while (!getShell().isDisposed()) {
	   	if (!display.readAndDispatch())
	    		display.sleep();
	  }
	}


	void close() {
		if (shell != null && !shell.isDisposed())
			shell.dispose();
	}
}

