Challenge: Resizing applet from within Java code. For example say the applet code calculates that the applet needs more space than it has been allocated, then how to go about it?

Last time when faced with this problem I solved it with a nifty piece of Javascript method. However I soon realized there were few issues with the approach.

First we made the applet dependent on external piece of Javascript method which creates undesirable dependency.

The main problem was when we wanted to embed multiple such applets in the same page. Obviously now I cannot use the same resize method, which is hardcoded to call the applet by name. Also I found that document['appletname'] logic fails when the applet is within a table. Then we have to refer to the applet using the hierarchy which we do not control. We also cannot have two applets with the same name as then only the first one executes.
So it was obvious we needed to pass the name of the applet to this method. But how to get the name?
I intuited correctly that since applet.getParameter used to get parameters from within the applet tag, it is possible that we can fetch the name of the applet using the same method. That turned out to be the case. So now I had this version where I passed the name of the applet to the resize method and it called the applet by its name ( applets['name'] ) and set the size as passed on by the parameters. This worked fine with both the browsers (Internet Explorer & Netscape). However I was still not satisfied. The external dependency was bugging me. The next step was to try to execute javascript code within Java itself, using the same LiveConnect bridge. My first attempt to set the size using JSObject.getMethod failed in IE. Apparently Internet Explorer doesn't support the method! Then I simply evaluated the whole code using eval. This worked well for both the browsers. I could get rid of the pesky javascript method - resize. Now finally I was happy. As I soon realized however there was still a little snag. The fixes don't work in Opera browser. But I am not too worried considering the market share of this browser.

To summarize the key line of code: jso.eval(applet + "width = " + width + ";");