Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Vivek - 22 Feb 2007 06:28 GMT
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
Sundar - 22 Feb 2007 08:56 GMT
> 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
Andrew Thompson - 22 Feb 2007 13:21 GMT
> > MyApplet apt=new MyApplet();
> > apt.init();
[quoted text clipped - 5 lines]
> 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$Fi3.1181624@wagner.videotron.net>

Andrew T.
Eric Sosman - 22 Feb 2007 14:54 GMT
> [...]
> 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.

Signature

Eric Sosman
esosman@acm-dot-org.invalid



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.