FileDocCategorySizeDatePackage
Ch08_02.javaAPI DocExample1971Thu Nov 20 12:02:46 GMT 2003org.eclipse.ch08

Ch08_02

public class Ch08_02 extends Object
author
Steven Holzner To change the template for this generated type comment go to Window>Preferences>Java>Code Generation>Code and Comments

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

			Display display = new Display();
			final Shell shell = new Shell(display);
			shell.setSize(300, 200);
			
			ToolBar toolbar = new ToolBar(shell, SWT.NONE);
			ToolItem item1 = new ToolItem(toolbar, SWT.PUSH);
			item1.setText("Now");
			ToolItem item2 = new ToolItem(toolbar, SWT.PUSH);
			item2.setText("is");
			ToolItem item3 = new ToolItem(toolbar, SWT.PUSH);
			item3.setText("the");
			ToolItem item4 = new ToolItem(toolbar, SWT.PUSH);
			item4.setText("time");
		    
		    toolbar.setBounds(0, 0, 200, 70);
			
			final Text text = new Text(shell, SWT.BORDER);
			text.setBounds(0, 100, 200, 25);
			
			Listener listener = new Listener() {
				public void handleEvent(Event event) {
					ToolItem item = (ToolItem)event.widget;
					String string = item.getText();
					if (string.equals("Now")) text.setText("You selected: Now"); 
					else if (string.equals("is")) text.setText("You selected: is");
					else if (string.equals("the")) text.setText("You selected: the");
					else if (string.equals("time")) text.setText("You selected: time");
			   }
			};
			
			item1.addListener(SWT.Selection, listener);
			item2.addListener(SWT.Selection, listener);
			item3.addListener(SWT.Selection, listener);
			item4.addListener(SWT.Selection, listener);

			shell.open();
		
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
			display.dispose();