FileDocCategorySizeDatePackage
GetImage.javaAPI DocExample1370Thu May 27 22:02:30 BST 2004None

GetImage

public class GetImage extends JApplet
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)

		JFrame f = new JFrame("GetImage");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GetImage myApplet = new GetImage();
		f.getContentPane().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);