Been playing with Java for quite a while now, and I just started working with JApplet
s/Applet
s. The problem I'm having is actually testing them. As you all probably know, most browsers cache the files, so if you update any of your code, the JApplet
s/Applet
s don't refresh. I've read that you can change the name of the HTML file that hosts the JApplet
/Applet
, and thus "trick" the browser into caching a "new" program. This doesn't always seem to work unfortunately.
Another method I see quite often is using the command appletviewer
in command line, but I've never been able to get this to work.
So I was wondering, how should I test my JApplet
s/Applet
s? What is the best way? How do you test your them?
The appletviewer is relatively easy to use. Here is the example from the applet info. page.
/* <!-- Defines the applet element used by the appletviewer. -->
<applet code='HelloWorld' width='200' height='100'></applet> */
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.invokeAndWait(r);
}
}
The Appleteer - applet test tool was designed by me to provide more feedback on an applet launch or the reasons for failure. Main features: