This is the code for my applet itself.
public class Screenshot extends JApplet {
BufferedImage screenshot;
/**
*
*/
private static final long serialVersionUID = 1L;
public void init() {
}
}
And that how I use it:
<applet code="Screenshot.class" archive="screenshot.jar" width="1" height="1"></applet>
Now, the problem is that the page with this applet never finishes loading for some reason.
What am I doing wrong? It is the first time I am using applets.
EDIT: I am apparently getting:
incompatible magic value 1013084704
I find the “never finishes loading” comment the most interesting. Can you clarify what you mean? The throbber keeps going or you get the animated Java logo and it never fades away?
TIP: Is screenshot.jar in the same directory as your hosted page? Does your web server have permissions to read the JAR so it can send it to the client? You can test this real quick by taking the URL in your browser and removing the page name (e.g. “/myapplet.html”) and replacing it with ‘screenshot.jar’ and see if your browser downloads it or reports a 404 (e.g. “/screenshot.jar”) — if it gives you a 404, then your browser cannot find/load your JAR.
If that doesn’t help there are a number of issues you could be having here with the actual Java runtime working inside your browser in the first place. With the advent of so many “blocker” extensions for browsers and Chrome/Firefox’s staunch position against running older Java runtimes when newer versions are available, it is entirely possible that your JRE/Applet runtime on your local machine is the one with the problem and not your Applet.
I would suggest grabbing an example Applet from a Sun tutorial (like this one) and putting it on your page and seeing if it works first. That way you start with a known quantity and troubleshoot from there.