How To invoke a Applet from a Java File ???

Discussion in 'Java' started by Vivek, Feb 22, 2007.

  1. Vivek

    Vivek Guest

    hi
    i have to run a Applet from a Java file.I tried this by creating an
    instance of the applet in the Java fole and calling init() over the
    Applet instance but was unable to run the Applet.
    i.e=>
    in Hello.java file

    MyApplet apt=new MyApplet();
    apt.init();

    Can anybody help me out to do this .
    Awaiting your Valuable response
    TIA and Regards
     
    Vivek, Feb 22, 2007
    #1
    1. Advertising

  2. Vivek

    Sundar Guest


    > MyApplet apt=new MyApplet();
    > apt.init();
    >



    Its not possible to load the applet by calling init() method. init()
    method is useful for initiation of some of the applet variables when
    the applet is loading. Hence it cannot be invoked like this.

    Why do you want to execute an applet from a Java application. It looks
    pretty strange for me.


    -Sundar
    http://heysundar.blogspot.com
     
    Sundar, Feb 22, 2007
    #2
    1. Advertising

  3. On Feb 22, 7:56 pm, "Sundar" <> wrote:
    > > MyApplet apt=new MyApplet();
    > > apt.init();

    >
    > Its not possible to load the applet by calling init() method. init()
    > method is useful for initiation of some of the applet variables when
    > the applet is loading. Hence it cannot be invoked like this.
    >
    > Why do you want to execute an applet from a Java application. It looks
    > pretty strange for me.


    Loading an applet from an application, is exactly
    what AppletViewer does (it is a JFrame).

    While it may seem strange to launch an applet
    outside a web page, it is becoming more common,
    as more and more obstacles are put in the way
    of a successful applet launch.

    Here is a recent example of how to do it..
    <http://groups.google.com/groups?selm=s3_Ch.
    50778$>

    Andrew T.
     
    Andrew Thompson, Feb 22, 2007
    #3
  4. Vivek

    Eric Sosman Guest

    Andrew Thompson wrote:
    > [...]
    > While it may seem strange to launch an applet
    > outside a web page, it is becoming more common,
    > as more and more obstacles are put in the way
    > of a successful applet launch.


    It doesn't seem strange to me (of course, strangeness
    is in the eye of the beholder). I've found it useful to have
    most of my GUI's extend JApplet, but also to write a simple
    main() that creates a JFrame, adds the JApplet to it, and
    calls init() and start(). This provides a bare-bones but
    adequate browser-like environment for the JApplet, and gives
    me the flexibility to use it as an actual applet or as an
    application (usually, as a Java Web Start application).

    There's very little that the two modes of execution need
    to do differently, once initialized. The in-a-JFrame version
    might want to manage a window title that the applet wouldn't,
    maybe a few menu items (like File->Exit) are present in one
    mode but absent in the other, ... By and large, the JApplet
    "just works" no matter which way it was actually started.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Feb 22, 2007
    #4
    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. webster
    Replies:
    0
    Views:
    884
    webster
    Jul 20, 2003
  2. Krista
    Replies:
    3
    Views:
    2,360
    Andrew Thompson
    Sep 15, 2004
  3. Archana
    Replies:
    1
    Views:
    1,406
    Andrew Thompson
    Oct 25, 2004
  4. yawnmoth
    Replies:
    1
    Views:
    926
    Andrew Thompson
    Aug 15, 2006
  5. besbello

    Can't invoke applet methods

    besbello, Sep 8, 2006, in forum: Java
    Replies:
    6
    Views:
    1,494
    Andrew Thompson
    Sep 8, 2006
Loading...

Share This Page