import java.applet.Applet;
import java.awt.Graphics;
import java.io.*;
import java.net.*;

/**
 *		A really simple example of an applet which has a string that can be set
 *		using live connect (or anything I guess) or alternatively set to the
 *		contents of a relative URL.
 */
public class LoadURLApplet extends Applet {

	private String myString;

	public void init() {
		myString = new String("Hello, world!");
	}

	public void paint(Graphics g) {
		g.drawString(myString, 25, 20);
	}
	public void setString(String aString) {
		myString = aString;
		repaint();
	}

	/**
	 *		Loads the contents of the relative URL, setting the string for
	 *		painting.
	 */
	public void loadURL(String relativeURL) {

		try {

			URL resolvePropertyLocation = new URL(getDocumentBase(),relativeURL);

			URLConnection connection = resolvePropertyLocation.openConnection();

			DataInputStream inStream =
									new DataInputStream(connection.getInputStream());
			String s;
			StringBuffer b = new StringBuffer();
			while((s=inStream.readLine())!=null)b.append(s);
			inStream.close();

			myString = b.toString();

		} catch(MalformedURLException e) {
			myString = "MalformedURLException exception";
		} catch(IOException io) {
			myString = "IOException exception";
		}
		repaint();
	}
}


