Run another program inside my program applet/canvas?

Hello!

I was thinking… in Java, is there a way to run another java program, and display this program INSIDE my program, via Canvas or something?

Thanks.

From what I know, there isn`t a way. But sombody, who is a coding expert, might show you some way to do that. :slight_smile:

Ook, thank you!

It depends… In case the java application you want to start is a swing application using a canvas as default viewport / panel, then you’d just put your Canvas from that application into your panel / applet.

…which means you can’t put an application you yourself have not created into your program. You have to have the source and it has to be Java.

You’re half correct, it has to be java (or at least for the method described), but I am pretty sure that you don’t need the source. I’m not 100% sure, but legal issues aside, you should be able to do the exact same thing with just a jar file AFAIK.

Let’s say the ‘external code’ has a ‘canvas-class’ (as opposed to a main-class).

You’d simply put the 3rd-party JAR in the classpath, and do this:


Class<?> clazz = Class.forName("third.party.SomeCanvasClass");
Canvas canvas = (Canvas)clazz.newInstance();

myPanel.add(canvas);