I\'ve been trying to run a simple applet that I created from the command line. I tried just doing:
C:\\java Applet
It obviously didn\'t w
I believe IDEs typically launch applets using the appletviewer, but using an unrestricted security policy (the appletviewer when launched from the command line is sand-boxed).
To launch the applet viewer from the command line, try this:
prompt> appletviewer TheApplet.java
See also the applet info. page for an example of using the applet element at the top of the source: E.G.
/*
*/
import javax.swing.*;
/** An 'Hello World' Swing based applet.
To compile and launch:
prompt> javac HelloWorld.java
prompt> appletviewer HelloWorld.java */
public class HelloWorld extends JApplet {
public void init() {
// Swing operations need to be performed on the EDT.
// The Runnable/invokeLater() ensures that happens.
Runnable r = new Runnable() {
public void run() {
// the crux of this simple applet
getContentPane().add( new JLabel("Hello World!") );
}
};
SwingUtilities.invokeLater(r);
}
}
When launched from the command line, the applet viewer will have an even more restrictive sand-box than is applied to an applet deployed in a browser.
An alternative to appletviewer is Appleteer which I can highly recommend, because it is better than appletviewer ( and I wrote it ;).