Embedding Java Applet into .html file

applet, html, java

Solution

Making applets work across a wide range of browsers is surprisingly hard. The tags weren't properly standardized in the early days, so Internet Explorer and Mozilla went separate directions.

Sun developed a generic JavaScript to handle all the specific browser quirks, so that you don't have to worry about browser compatibility.

Add this to your `<head>` section:

<script src="//www.java.com/js/deployJava.js"></script>

And this to `<body>` section:

<script>
    var attributes = {codebase: 'http://my.url/my/path/to/codebase',
                      code: 'my.main.Applet.class',
                      archive: 'my-archive.jar',
                      width: '800', 
                      height: '600'};
    var parameters = {java_arguments: '-Xmx256m'}; // customize per your needs
    var version = '1.5'; // JDK version
    deployJava.runApplet(attributes, parameters, version);
</script>

See Java™ Rich Internet Applications Deployment Advice for a detailed explanation of the script and all the possible options.

Problem

I am having trouble embedding my applet into a webpage. I don't think I'm doing it correctly. * I have my html file in the same directory as my .class files My main method is in CardApp class This is my html code ``` <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>TestJCardBet.html</title> </head> <body> <applet codebase="" code="CardApp.class" height="400" width="500"></applet> </body> </html> ```

Original source