Search code examples
javaeclipseswingappletjapplet

Java applet doesn't draw or accept mouse inputs in browser, but does in Eclipse Appletviewer


I'm doing a personal project called "Electromagnetic Field Hockey" (named after Electric Field Hockey on The University of Colorado's PhET website). I've decided to port the application to a java applet on my website.

The problem is that the applet will not accept any mouse input, and I don't even know if it started because the graphics disappear when I switch tabs and back. I know the applet is finding the code and codebase because the applet initializes and renders the first frame of the graphics correctly, then does nothing. What's peculiar is the applet works fine in Eclipse's Appletviewer. I suspect that the culprit is the start() method, which I think somehow isn't being executed in a browser.

In case it helps, you can find the applet at http://leo.scruffohio.net/programs/EMFieldHockey.html. I tested it with Firefox on Linux and Safari on a Mac so it's not a system-dependent issue. Note that the application works when you run the jar file (located at http://leo.scruffohio.net/programs/java/thebombzen-emhockey-dev3.jar).

My applet code is very simple:

public class EMFieldHockeyApplet extends JApplet {

    private static final long serialVersionUID = 8145754973708683690L;

    @Override
    public void init() {
        this.setBackground(Color.WHITE);
        this.setLayout(new GridLayout());
        this.add(ElectromagneticFieldHockey.getInstance());
        // that's the main application JPanel
    }

    @Override
    public void start() {
        ElectromagneticFieldHockey.start();
    }

    @Override
    public void stop(){
        ElectromagneticFieldHockey.stop();
    }

}

Solution

  • It seems that problem in your jar signing, try with it

    http://docs.oracle.com/javase/tutorial/deployment/jar/signing.html