Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed jar in HTML

Tags:

java

html

applet

There are a lot of resources on this already but I just can't seem to get it to work. What am I doing wrong? The jar file is at:

http://www.alexandertechniqueatlantic.ca/multimedia/AT-web-presentation-imp.jar

And the code I am using to embed is:

<APPLET ARCHIVE="multimedia/AT-web-presentation-imp.jar" 
        CODE="ImpViewer.class" 
        WIDTH=100% 
        HEIGHT=100%>
</APPLET>

The test page I am using is at:

http://www.alexandertechniqueatlantic.ca/test.php

When I download the jar it runs fine, so I am certain the problem is only with the html embedding. Pleas help!

Also, I get the following error:

java.lang.ClassCastException: ImpViewer cannot be cast to java.applet.Applet

like image 307
Bill Software Engineer Avatar asked Sep 23 '11 15:09

Bill Software Engineer


1 Answers

java.lang.ClassCastException: ImpViewer cannot be cast to java.applet.Applet

The 'applet' is not an applet.

BTW - nice UI. Like the way the red splash fades in to the 'Welcome Introductory Workshop' page. Very smooth.

Launch it from a link using Java Web Start (& please don't try and cram such a beautiful UI into a web page).


If the client insists on the GUI being crammed into a web site then (slap them for me &) try this hack.

/*
<APPLET 
    ARCHIVE="AT-web-presentation-imp.jar" 
    CODE="ImpViewerApplet" 
    WIDTH=720 
    HEIGHT=564>
</APPLET>
*/
import java.awt.*;
import java.applet.*;
import java.util.*;

public class ImpViewerApplet extends Applet {

    public void init() {
        setLayout(new BorderLayout());
        Window[] all = Window.getWindows();
        ArrayList<Window> allList = new ArrayList<Window>();
        for (Window window : all) {
            allList.add(window);
        }
        String[] args = {};
        ImpViewer iv = new ImpViewer(); 
        iv.main(args);

        all = Window.getWindows();
        for (Window window : all) {
            if (!allList.contains(window) && window.isVisible()) {
                if (window instanceof Frame) {
                    Frame f = (Frame)window;
                    Component[] allComp = f.getComponents();
                    Component c = f.getComponents()[0];
                    f.remove(c);
                    f.setVisible(false);
                    add(c);
                    validate();
                }
            }
        }
    }
}

The emphasis is on the word 'hack'.

  1. The Frame will flash onto screen before disappearing.
  2. It will only work at 720x564 px, unlike the java.awt.Frame which was resizable to any size. But then, your '100%' width/height was being a bit optimistic anyway. Some browsers will honour those constraints, others will not.
like image 146
Andrew Thompson Avatar answered Sep 28 '22 15:09

Andrew Thompson