?
Solved

Applet and ClassLoader

Posted on 1997-08-22
1
Medium Priority
?
335 Views
Last Modified: 2013-12-29
Is it possible to create an Applet which could load and execute Applets from another URL? I know about showDocument-method, but I would like to execute Applets in my own Applet's Frames. Is it possible to use some kind of ClassLoader class to do this?
0
Comment
Question by:Klaavu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
russgold earned 450 total points
ID: 1225621
Only partially possible. You may load and execute another Applet as long as the other Applet is available in your applet's CLASSPATH.  Applet's are subclasses of containers, and may be treated as such.  Note that you cannot use a URL to do this, since URLs specify pages, not applets.

The problem is twofold. You can only access files of any kind - even via URL - if they come from your applet's home site.  But even then, your non-overridable ClassLoader is restricted to the CLASSPATH specified in your HTML <APPLET> tag.

Here is some sample code that works if you meet all the necessary conditions:

try {
    Class appletClass = Class. forName( "AnotherApplet" );
    Object anotherApplet = appletClass. newInstance();
    if (anotherApplet instanceof Applet) {
        appletContainer. add( anotherApplet );
        anotherApplet. init();
        anotherApplet. start();
        }
    }
catch( Throwable t ) {
    // handle ClassNotFoundException, InstantiationException,
    // and IllegalAccessException
    }

you will have to make sure that the applet's start() and stop() methods are called at the appropriate time.

Note: this
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question