Java in Java

  • Thread starter Dirk Bruere at NeoPax
  • Start date
D

Daniel Pitts

Dirk said:
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.
 
R

Roedy Green

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
 
A

Arne Vajhøj

Roedy said:
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
 
A

Andrew Thompson

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. ;-)
 
A

Andrew Thompson

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=10259860#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?
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Official Java Classes 10
Java in Browser 57
Can an Applet beep? 4
Free keyboard applet 5
Change character in string 105
ListModel name 10
Accessing static field 21
Sorting a JList 4

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top