import java.applet.Applet;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.Button;
import java.awt.TextField;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GfxViewer extends Applet implements ActionListener {
	protected TextField graphicsName;
	Image imgToDisplay = null;

	public void init() {
		graphicsName = new TextField ("enter URL of image to view", 50);
		Button loadBtn = new Button ("view");
		GridBagLayout gbl = new GridBagLayout();
		setLayout(gbl);

		loadBtn.addActionListener(this);
		add(loadBtn);
		add(graphicsName);
	} //init

	public void actionPerformed(ActionEvent event) {
		imgToDisplay = getImage( getDocumentBase(), graphicsName.getText() );
		repaint();
	} //actionPerformed()

	public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
		repaint();
 		if ((infoflags &  ImageObserver.SOMEBITS) != 0) {
   		System.out.println("part just loaded:"+x+" "+y+" "+ width+" "+height);
			return true;
		} //if
		if ((infoflags &  ImageObserver.ALLBITS) != 0) {
   		System.out.println("image loaded completely");
 			return false;
 		} //if
		//gets here when height and width of image is available
 		return true;
   } //imageUpdate()

	public void paint(Graphics g) {
		if (imgToDisplay != null) {
			g.drawImage(imgToDisplay, 1, 1, this);
		} //if
	} //paint
} //class GfxViewer