Embedding an Applet

I need to contain an Applet in my application. I have tried to do this by embedding the applet as a StreamResource, as in
[url]

http://itmill.com/documentation/itmill-toolkit-5-reference-manual/ch03s05.html#section.resources.stream

[/url]
and then construct the input stream as html as I would in a servlet. So I have something like:


public class AppletSource implements StreamResource.StreamSource {
public InputStream getStream() {
StringBuffer buf = new StringBuffer();
.....
.....
buf.append("<PARAM NAME=\"type\" VALUE=\"application/x-java-applet;version=1.5.0\">");
buf.append("<EMBED type=\"application/x-java-applet;version=1.5.0\"");      
buf.append("width=\"100%\" height=\"100%\" align=\"baseline\"");
.....
.....
InputStream in = new ByteArrayInputStream(buf.toString().getBytes() );
return in;

Then inside the window I call


StreamResource.StreamSource appletSource = new AppletSource(uName,loc);
StreamResource appletResource = new StreamResource(appletSource,"appletname.applet",application);
....
layout.addComponent(embed);
setLayout(layout);

But it doesn’t work, and only a blank screen appears. In fact, when I try the image example from the above page, it doesn’t work either. There are no exceptions thrown, and it seems the getStream() method is never even called.

Is there something I should add to my code to make it work? Also if there is a better way to include an applet I’d appreciate any advice.

Hi,

The idea is to embed applets using the Embedded -component, but without making the html tags yourself (you give the .jar to Embedded, it handles the rest). However, this feature is not implemented yet: http://dev.itmill.com/ticket/1145

It could be possible to use the Embedded in browser-mode (embedded.setType(Embedded.TYPE_BROWSER), will produce an iframe to display the content), but I have not tried it.

A Label may also be used to produce the needed html to show the applet, depending on your needs…

Best Regards,
Marc