Image

Using ClassLoader - Loading a User defined class from a string of its name

I'm still working on that Kicker application.

Here's what I want to have it do.

There's a class AppletLoader which keeps track of a database of all available KickerApplets. The KickerApplets themselves are children of JPanel.

Now, the idea is that a developer can write their own KickerApplet, drop it into the directory where the other applets are located, add an entry in the database, and from that point forward, the application can use that KickerApplet.

Now, my proposed solution is to have AppletLoader extend ClassLoader, and add this: KickerApplet loadApplet(String name).
My method for this is currently:
public KickerApplet loadApplet(String name) {
    try {
      Class c = loadClass(name, true);
      KickerApplet a = (KickerApplet)c.newInstance();
      return a;
    } catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
  }


For my testing purposes, I'm using a KickerApplet already available to the application, "ControlApplet". Every time I use this function though, it bails with a "ClassNotFoundException"


What I'm really trying to get at here, is what method should I use to load an instance of a class by its name alone? Am I on the right track here? Google's not helping much at the moment, mostly because I can't figure out a search for this.

[edit]Never mind- found it, but this is still a neet topic anyway. Some useful source[/edit]