import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class ImageDemo {

	public static Display myDisplay;
	public static boolean internalCall = false;

	public static void main(String[] args) {
		internalCall = true;
		myDisplay = new Display();
		ImageDemo id = new ImageDemo();
		id.runDemo(myDisplay);
	}
	
	public void runDemo(Display display) {
		myDisplay = display;
		Shell shell = new Shell(display);
		shell.setSize(140,100);
		shell.setText("Image Demo");

		//load an image from a JPEG file
		Image img = new Image(display, "EclipseBannerPic.jpg");		

//		//roughly equivalent code that works for loading an image from a JAR file
//		InputStream is = getClass().getResourceAsStream("EclipseBannerPic.jpg");
//		Image img = new Image(display, is);
		
		//open the shell, so we can draw on it
		shell.open();

		//get a Graphics Context
		GC gc = new GC(shell);
		
		//draw the image at a specific x and y location
		gc.drawImage(img, 0, 0);
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		
		//dispose of the image object
		img.dispose();

		if (internalCall) display.dispose();

	}
	
}
