This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Applet an application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Applet an application" Watch "Applet an application" New topic
Author

Applet an application

Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
I have an requirement to run my Swing Japplet as an Applet or Application. Any help will be greatly appreciated.
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
JApplet/Applet are both descendants of Component, so you can add them to a Swing container.
What I have done is create my applet like you normally would first. Then, to make it an applicaiton, simply create a new class with a JFrame, and add the applet as a component to that JFrame. You have to call the applet's init() and start() methods at the start of the application. But after that, it will work exactly like it did in a browser. When you are quitting your application, you proably should call stop() on the applet, to mimick what a browser does when stopping the applet.
But since an applet is really just a component, you can treat it like you would any other AWT/Swing component in your application.


Rob
SCJP 1.4
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Well... that is pretty much true... the only difference is that the browser provides an AppletContext for the Applet to live in... there are some methods that will throw exceptions if an Applet is run outside of it's AppletContext (mostly things that deal with the applet's environment, like getting the current URL, or loading an Image...), so if you need to do any of these things you'll either need to build an AppletContext to put the Applet in, or you'll need to build some flags in your applet that get set based on how it is launched and test before calling any fuctions that rely on the AppletContext.

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet an application