wood burning stoves 2.0*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Applet outside a browser>" Watch "Applet outside a browser>" New topic
Author

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)
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!
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
Bartender

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...

-Nate


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

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
    
    1
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,
<PRE>
class MyApplet extends Applet { .... }
class Standalone extends Frame {
Applet myApplet;
Standalone() {
add(myApplet = new MyApplet());
myApplet.init();
myApplet.start();
}
public static void main(String[] args) {
new Standalone();
}
}
</PRE>
Then you can run it either in a browser, with appletviewer, or from the command line with "java Standalone".
Regards
Geoffrey

------------------
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
 
Consider Paul's rocket mass heater.
 
subject: Applet outside a browser>