/*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* Copyright (C) 1996  IDS Software.  All Rights Reserved.
*
*  Module:	BugTest.java
*
*  Comment:	Internet Explorer Class.forName() Bug Test Program
*
*		When Class.forName(String className) is called, 
*		Netscape Navigator will download and initialize
*		static members of "className". The output in the
*		text window is "SMember".
*
*		However, it seems that Internet Explorer chooses to 
*		delay static member initialization until the first 
*		instantiation via the new operator. The output in the
*		text window is "<empty>".
*
*/

import java.applet.*;
import java.awt.*;

class SManager {
	public static String className = "Static class members are not properly initialized \nwhen Class.forName(\"SMember\") is called.";
	public static String getMember() {
		return className;
	}
}
class SMember {
	//public static SMember self = new SMember();
	public SMember() {
	}
	static {
		SManager.className = "This is a correct result.";
	}
}

public class BugTest extends Applet implements Runnable {

	private TextArea textWin = null;
	private Thread theThread = null;
	private TextField status = null;
   
	public void run() {

	  try {
		Class.forName("SMember");
		String s = SManager.getMember();
		println(s);

		status.setText("Done.");
	  }
	  catch (Throwable e) {
		status.setText("Exception: " + e.toString());
	  }
	}

	public void init() {
		super.init();
		if (textWin == null) {
			setLayout(new BorderLayout());
			Font fn = new Font("Courier", Font.PLAIN, 12);
			textWin = new TextArea();
			status  = new TextField("Please wait...");
			textWin.setFont(fn);
			add("Center", textWin);
			add("South", status);
		}
	}

	public void start() {
		textWin.setText("");
		if (theThread == null) {
			theThread = new Thread(this);
			theThread.start();
		}
	}
	public void stop() {
		if ((theThread != null) && theThread.isAlive()) 
			theThread.stop();
		theThread = null;
	}

	public void print(String s) {
		textWin.appendText(s);
	}
	public void println(String s) {
		textWin.appendText(s + '\n');
	}
	public void println() {
		textWin.appendText("\n");
	}

}
