f



Java in Java

Is it possible to download a Java app (applet etc?) and run it inside a 
desktop Java app?

-- 
Dirk

http://www.transcendence.me.uk/ - Transcendence UK
http://www.theconsensus.org/ - A UK political party
http://www.onetribe.me.uk/wordpress/?cat=5 - Our podcasts on weird stuff
0
dirk.bruere (468)
5/8/2009 1:03:53 PM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

10 Replies
1661 Views

Similar Articles

[PageSpeed] 1

Dirk Bruere at NeoPax wrote:
> Is it possible to download a Java app (applet etc?) and run it inside a 
> desktop Java app?
> 
Quite likely, but you won't necessarily get the same security model, 
unless you were careful about it.

-- 
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
0
5/8/2009 3:17:33 PM
Dirk Bruere at NeoPax wrote:
> Is it possible to download a Java app (applet etc?) and run it inside a 
> desktop Java app?
> 


Yes, you can just download the code and run it.  There are Jar classes 
for manipulating this.

<http://java.sun.com/javase/6/docs/api/java/util/jar/JarFile.html>

You may need to use a Classloader as well, I haven't actually tried this.


0
markspace (1144)
5/8/2009 4:13:40 PM
Mark Space wrote:
> Dirk Bruere at NeoPax wrote:
>> Is it possible to download a Java app (applet etc?) and run it inside 
>> a desktop Java app?
>>
> 
> 
> Yes, you can just download the code and run it.  There are Jar classes 
> for manipulating this.
> 
> <http://java.sun.com/javase/6/docs/api/java/util/jar/JarFile.html>
> 
> You may need to use a Classloader as well, I haven't actually tried this.
> 
> 

Take a look here and the next page in this series.  It might help:

<http://java.sun.com/docs/books/tutorial/deployment/jar/jarclassloader.html>
0
markspace (1144)
5/8/2009 4:26:07 PM
On Fri, 08 May 2009 14:03:53 +0100, Dirk Bruere at NeoPax
<dirk.bruere@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>Is it possible to download a Java app (applet etc?) and run it inside a 
>desktop Java app?

Very easy.  All you need is Class.forName

See http://mindprod.com/jgloss/classforname.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com

"Species evolve exactly as if they were adapting as best they could to a changing world, and not at all as if they were moving toward a set goal." 
~ George Gaylord Simpson
0
see_website (5876)
5/8/2009 9:03:17 PM
On Fri, 08 May 2009 14:03:53 +0100, Dirk Bruere at NeoPax
<dirk.bruere@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>Is it possible to download a Java app (applet etc?) and run it inside a 
>desktop Java app?

It is easy if there is some cooperation, the add on implements an
interface. Harder if not. Then you need reflection.

See http://mindprod.com/jgloss/reflection.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com

"Species evolve exactly as if they were adapting as best they could to a changing world, and not at all as if they were moving toward a set goal." 
~ George Gaylord Simpson
0
see_website (5876)
5/8/2009 9:56:29 PM
Dirk Bruere at NeoPax wrote:
> Is it possible to download a Java app (applet etc?) and run it inside a 
> desktop Java app?

Sure.

That is what Andrew does in http://pscode.org/appleteer/ !

Arne
0
arne6 (9808)
5/8/2009 10:28:40 PM
Roedy Green wrote:
> On Fri, 08 May 2009 14:03:53 +0100, Dirk Bruere at NeoPax
> <dirk.bruere@gmail.com> wrote, quoted or indirectly quoted someone who
> said :
>> Is it possible to download a Java app (applet etc?) and run it inside a 
>> desktop Java app?
> 
> It is easy if there is some cooperation, the add on implements an
> interface. Harder if not.

Given that apps has a static main method and applets extend either
Applet or JApplet, then an interface should not be needed.

Arne
0
arne6 (9808)
5/8/2009 10:30:01 PM
On May 9, 8:28=A0am, Arne Vajh=F8j <a...@vajhoej.dk> wrote:
> Dirk Bruere at NeoPax wrote:
>
> > Is it possible to download a Java app (applet etc?) and run it inside a
> > desktop Java app?
>
> Sure.
>
> That is what Andrew does in http://pscode.org/appleteer/ !

Yep.

To the OP: Note that AppletViewer is also a 'Java desktop
app.', and is what Sun uses to launch webstart based applets,
and the new 'draggable applets' if they are dragged off the
web page.

(whispers)  Appleteer is better, though.  ;-)

--
Andrew T.
pscode.org
0
andrewthommo (3108)
5/9/2009 1:31:06 AM
On May 8, 11:03=A0pm, Dirk Bruere at NeoPax <dirk.bru...@gmail.com>
wrote:
> Is it possible to download a Java app (applet etc?) and run it inside a
> desktop Java app?

For the first part, get an URLClassLoader that
points to the applet.

Here is a simplistic* SSCCE that does the second part.
<http://forums.sun.com/thread.jspa?messageID=3D10259860#10259860>

* Trouble starts if the applet uses parameters,
does not have a preferred size, uses any of the
applet context methods..

I am a bit confused by your use of 'Java app (applet
etc?)' what else besides an applet are you looking to
run?

--
Andrew T.
pscode.org
0
andrewthommo (3108)
5/9/2009 6:10:56 AM
On Fri, 08 May 2009 09:13:40 -0700, Mark Space
<markspace@sbc.global.net> wrote, quoted or indirectly quoted someone
who said :

>Dirk Bruere at NeoPax wrote:
>> Is it possible to download a Java app (applet etc?) and run it inside a 
>> desktop Java app?
>> 
 If you know the name at compile time, you just invoke the method as
if it were part of the original program. Just make sure the jar is on
the classpath.


If you don't know the name, and you just have a String you concocted
at run time, you can use Class.forName and newInstance. See
http://mindprod.com/jgloss/classforname.html

If you don't even know the method names and parameters at compile
time, you need to use reflection.
http://mindprod.com/jgloss/reflection.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com

Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, �How would I develop if it were my money?� I�m amazed how many theoretical arguments evaporate when faced with this question. 
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
0
Roedy
3/23/2010 2:02:30 PM
Reply: