jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Applet outside a browser> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Applet outside a browser>" Watch "Applet outside a browser>" New topic

Applet outside a browser>

cardwell cupp
Ranch Hand

Joined: Aug 16, 2001
Posts: 66
Is it possible to run an applet outside a browser. If so, how do you do it>?
Thanks all
cardwell (greenest horn)
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I don't think so. The thing that makes Applet an Applet is that you do no have a main method. That the browser do this for you.
You can use Appletviewer if you don't feel like open a browser for your applet.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Since Applet extends Panel, you can add it into any GUI just like a Panel. All the applet specific stuff ( like getAppletContext(), getImage(), etc. ) won't work though...


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
You can view and applet in an applet-viewer outside of a browser. An applet viewer is a tool that implements the same behaviors towards applets as a browser would.
The contract that a browser has with an applet is that it will understand how to use 4 methods.

It will begin the applet by calling the init() method.
Every time the page is redisplayed (for instance after the browser has been minimized and then re-displayed) it will call the start() method allowing the applet to re-kickoff any animations or audios.
It will call the stop() method every time the page is not being displayed (like when it gets minimized). This allows you the chance to stop animations which would waste resources when not been viewed, and turn off audios which might annoy your user if the applet is not currently being displayed.
It will call the destroy() method to release any resources when the applet is completed in some manner.
[This message has been edited by Cindy Glass (edited September 13, 2001).]

"JavaRanch, where the deer and the Certified play" - David O'Meara
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
Yes, you can do this by creating a main() method in a separate class. Remember that Applet extends Panel, so you can add an Applet to a Frame. For example,
class MyApplet extends Applet { .... }
class Standalone extends Frame {
Applet myApplet;
Standalone() {
add(myApplet = new MyApplet());
public static void main(String[] args) {
new Standalone();
Then you can run it either in a browser, with appletviewer, or from the command line with "java Standalone".

Sun Certified Programmer for the Java 2 Platform
[This message has been edited by Geoffrey Falk (edited September 14, 2001).]
[This message has been edited by Geoffrey Falk (edited September 14, 2001).]

Sun Certified Programmer for the Java 2 Platform
I agree. Here's the link: http://aspose.com/file-tools
subject: Applet outside a browser>
It's not a secret anymore!