FileDocCategorySizeDatePackage
ClassForName.javaAPI DocExample650Sat Nov 25 12:55:22 GMT 2000None

ClassForName

public class ClassForName extends Object
Demonstrate "classFor" to create an instance of an object.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] av)

		Class  c = null;
		Object o = null;
		try {
			// Load the class, return a Class for it
			c = Class.forName("java.awt.Frame");
			// Construct an object, as if new Type()
			o = c.newInstance();
		} catch (Exception e) {
			System.err.println("That didn't work. " +
				" Try something else" + e);
		}
		if (o != null && o instanceof Frame) {
			Frame f = (Frame)o;
			f.setTitle("Testing");
			f.setVisible(true);
		} else throw new 
			IllegalArgumentException("Huh? What gives?");