import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.*;

public class GCDemo2 {

	public static Display myDisplay;
	public static boolean internalCall = false;

	public static void main(String[] args) {
		internalCall = true;
		myDisplay = new Display();
		GCDemo2 gcd = new GCDemo2();
		gcd.runDemo(myDisplay);
	}

	public void runDemo(Display display) {
		myDisplay = display;
		Shell shell = new Shell(display);
		shell.setSize(200, 240);
		shell.setText("GC Demo2");

		Canvas canvas = new Canvas(shell, SWT.BORDER);

		canvas.setSize(150, 150);
		canvas.setLocation(20, 20);

		//add a paintlistener so that repaint events
		//will redraw the rectangle when necessary
		canvas.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				GC gc = e.gc;
				gc.drawRectangle(3, 5, 20, 25);
			}
		});

		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}

		if (internalCall) display.dispose();

	}

}
