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

V

Vivek

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
 
S

Sundar

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
 
A

Andrew Thompson

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.
[email protected]>

Andrew T.
 
E

Eric Sosman

Andrew said:
[...]
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.
 

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

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top