[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Applet and ClassLoader

Posted on 1997-08-22
1
Medium Priority
?
339 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
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month17 days, 20 hours left to enroll

830 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