Java in Java

Discussion in 'Java' started by Dirk Bruere at NeoPax, May 8, 2009.

  1. Dirk Bruere at NeoPax, May 8, 2009
    #1
    1. Advertising

  2. Dirk Bruere at NeoPax

    Daniel Pitts Guest

    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/>
     
    Daniel Pitts, May 8, 2009
    #2
    1. Advertising

  3. Dirk Bruere at NeoPax

    Mark Space Guest

    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.
     
    Mark Space, May 8, 2009
    #3
  4. Dirk Bruere at NeoPax

    Mark Space Guest

    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>
     
    Mark Space, May 8, 2009
    #4
  5. Dirk Bruere at NeoPax

    Roedy Green Guest

    On Fri, 08 May 2009 14:03:53 +0100, Dirk Bruere at NeoPax
    <> 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
     
    Roedy Green, May 8, 2009
    #5
  6. Dirk Bruere at NeoPax

    Roedy Green Guest

    On Fri, 08 May 2009 14:03:53 +0100, Dirk Bruere at NeoPax
    <> 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
     
    Roedy Green, May 8, 2009
    #6
  7. Dirk Bruere at NeoPax

    Arne Vajhøj Guest

    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
     
    Arne Vajhøj, May 8, 2009
    #7
  8. Dirk Bruere at NeoPax

    Arne Vajhøj Guest

    Roedy Green wrote:
    > On Fri, 08 May 2009 14:03:53 +0100, Dirk Bruere at NeoPax
    > <> 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
     
    Arne Vajhøj, May 8, 2009
    #8
  9. On May 9, 8:28 am, Arne Vajhøj <> 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
     
    Andrew Thompson, May 9, 2009
    #9
  10. On May 8, 11:03 pm, Dirk Bruere at NeoPax <>
    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=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?

    --
    Andrew T.
    pscode.org
     
    Andrew Thompson, May 9, 2009
    #10
  11. Dirk Bruere at NeoPax

    Roedy Green Guest

    On Fri, 08 May 2009 09:13:40 -0700, Mark Space
    <> 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.
     
    Roedy Green, Mar 23, 2010
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Novice
    Replies:
    1
    Views:
    1,152
    Mike Schilling
    Jul 19, 2003
  2. Michael Kintner
    Replies:
    0
    Views:
    851
    Michael Kintner
    Nov 30, 2003
  3. Ilias Lazaridis
    Replies:
    0
    Views:
    577
    Ilias Lazaridis
    Feb 1, 2005
  4. manish sahu
    Replies:
    3
    Views:
    1,009
  5. Isaac
    Replies:
    0
    Views:
    378
    Isaac
    Jan 20, 2011
Loading...

Share This Page