I have struggled for two days trying to get gwt-ai working on Java 6,
with no success. I didn't have any remaining time to "fix it" so I
came up with a quite simple solution integrating the applet with a
plain simple HTML widget.
So, here's how you do it in the GWT component:
<pre>
private final String appletId = "MyApplet";
...
appletWidget = new HTML();
appletWidget.setHTML(createAppletHTML());
mainPanel.add(appletWidget);
initWidget(mainPanel);
...
private String createAppletHTML() {
StringBuffer buff = new StringBuffer();
buff.append("<!--[if !IE]> -->");
buff.append("<object classid=
\"java:com.optilab.sargas.applets.PatternEditorApplet.class\"");
buff.append(" type=\"application/x-java-applet\"");
buff.append(" archive=\"" + GWT.getHostPageBaseURL() +
"MyApplet.jar, " + GWT.getHostPageBaseURL() + "dependencyLibrary.jar
\"");
buff.append(" height=\"600\" width=\"800\"");
buff.append(" id=\"" + appletId + "\" name=\"" + appletId +
"\"");
buff.append(" >");
buff.append("<param name=\"code\" value=
\"com.optilab.sargas.applets.MyApplet.class\" />");
//buff.append("<param name=\"archive\" value=\"" +
GWT.getHostPageBaseURL() + "MyApplet.jar\" />");
buff.append("<param name=\"persistState\" value=\"false\" /
>");
buff.append("<param name=\"mayscript\" value=\"yes\" />");
buff.append("<param name=\"scriptable\" value=\"true\" />");
buff.append("<param name=\"servletUrl\" value=\"" +
GWT.getModuleBaseURL() + "someservlet\" />");
buff.append("<center>");
buff.append("<p><strong>PatternEditorApplet content requires
Java 1.5 or higher, which your browser does not appear to have.</
strong></p>");
buff.append("<p><a href=\"
http://www.java.com/en/download/
index.jsp\">Get the latest Java Plug-in.</a></p>");
buff.append("</center>");
buff.append("</object>");
buff.append("<!--<![endif]-->");
buff.append("<!--[if IE]>");
buff.append("<object classid=\"clsid:8AD9C840-044E-11D1-
B3E9-00805F499D93\"");
buff.append(" codebase=\"
http://java.sun.com/products/plugin/
autodl/jinstall-1_4-windows-i586.cab#Version=1,4,0,0\"");
buff.append(" height=\"600\" width=\"800\"");
buff.append(" id=\"" + appletId + "\" name=\"" + appletId +
"\"");
buff.append(" >");
buff.append("<param name=\"code\" value=
\"com.optilab.sargas.applets.MyApplet.class\" />");
buff.append("<param name=\"archive\" value=\"" +
GWT.getHostPageBaseURL() + "MyApplet.jar, " + GWT.getHostPageBaseURL()
+ "dependencyLibrary.jar\" />");
buff.append("<param name=\"persistState\" value=\"false\" /
>");
buff.append("<param name=\"mayscript\" value=\"yes\" />");
buff.append("<param name=\"scriptable\" value=\"true\" />");
buff.append("<param name=\"servletUrl\" value=\"" +
GWT.getModuleBaseURL() + "someservlet\" />");
buff.append("<center>");
buff.append("<p><strong>PatternEditorApplet content requires
Java 1.5 or higher, which your browser does not appear to have.</
strong></p>");
buff.append("<p><a href=\"
http://www.java.com/en/download/
index.jsp\">Get the latest Java Plug-in.</a></p>");
buff.append("</center>");
buff.append("</object>");
buff.append("<![endif]-->");
return buff.toString();
}
</pre>
Explanation:
MyApplet.jar is your applet,
dependencyLibrary.jar is some library (if you need it) that will also
be included at applet runtime
the servletUrl parameter is passed in case you need your applet to
communicate with some service (if you need it)
If you want to communicate with the applet from GWT:
<pre>
public static native void invokeAppletMethod(String appletId) /*-{
$doc.getElementById(appletId).somePublicAppletMethod();
}-*/;
</pre>
The solution works on IE and Firefox and I have also tested it in
Safari (it works).
Hope this will help all the lost souls around here ;)
Best regards,
Kris
keywords: gwt applet integration communication