FileDocCategorySizeDatePackage
GetImage.javaAPI DocExample1318Thu Mar 29 23:12:10 BST 2001None

GetImage

public class GetImage extends Applet
This program, which can be an Applet or an Application, shows a form of Toolkit.getImage() which works the same in either Applet or Application!

Fields Summary
Image
image
Constructors Summary
Methods Summary
public voidinit()

		loadImage();
	
public voidloadImage()

		// Applet-only version:
		// Image = getImage(getCodeBase(), "Duke.gif");
		
		// Portable version: getClass().getResource() works in either
		// applet or application, 1.1 or 1.3, returns URL for file name.
		URL url = getClass().getResource("Duke.gif");
		image = getToolkit().getImage(url);
		// Shorter portable version: same but avoids temporary variables
		// image = getToolkit().getImage(getClass().getResource("Duke.gif"));
	
public static voidmain(java.lang.String[] args)

		Frame f = new Frame("GetImage");
        f.addWindowListener(new WindowCloser(f));
		GetImage myApplet = new GetImage();
		f.add(myApplet);
		myApplet.init();
		f.setSize(100, 100);
		f.setVisible(true);
		myApplet.start();
	
public voidpaint(java.awt.Graphics g)

		g.drawImage(image, 20, 20, this);