Challenge: Resizing applet from within Java code. Desafío: Cambiar el tamaño de applet de Java en código. For example say the applet code calculates that the applet needs more space than it has been allocated, then how to go about it? Por ejemplo dicen que el código applet calcula que el applet necesita más espacio de lo que ha sido asignado, entonces cómo hacerlo?

Last time when faced with this problem La última vez cuando se enfrentan a este problema I solved it with a nifty piece of Javascript method I resolverse con una excelente pieza de Javascript método . However I soon realized there were few issues with the approach. Sin embargo pronto se dieron cuenta que había algunas cuestiones con el planteamiento.

First we made the applet dependent on external piece of Javascript method which creates undesirable dependency. En primer lugar hemos hecho el applet depende de la pieza externa de Javascript método que crea dependencia indeseable.

The main problem was when we wanted to embed multiple such applets in the same page. El principal problema fue cuando quisimos integrar múltiples tales applets en la misma página. Obviously now I cannot use the same resize method, which is hardcoded to call the applet by name. Es evidente que ahora no puedo utilizar el mismo tamaño de método, que es hardcoded llamar al applet por su nombre. Also I found that document['appletname'] logic fails when the applet is within a table. También me di cuenta de que el documento [ 'appletname'] lógica falla cuando el applet se encuentra dentro de una tabla. Then we have to refer to the applet using the hierarchy which we do not control. Entonces tenemos que hacer referencia a la applet utilizando la jerarquía que no controlamos. We also cannot have two applets with the same name as then only the first one executes. Tampoco podemos tener dos applets con el mismo nombre que entonces sólo el primero se ejecuta.
So it was obvious we needed to pass the name of the applet to this method. Por lo tanto, era obvio que necesitábamos para pasar el nombre del applet a este método. But how to get the name? Pero, ¿cómo obtener el nombre?
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. I intuited correctamente que, desde applet.getParameter usado para obtener los parámetros dentro de la etiqueta de applet, es posible que podamos obtener el nombre del applet utilizando el mismo método. That turned out to be the case. Que resultó ser el caso. 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. Así que ahora he tenido esta versión que me pasó el nombre del applet al tamaño de método y el applet llamado por su nombre (applets [ 'nombre']) y establecer el tamaño, tal como fue aprobado por los parámetros. This worked fine with both the browsers ( Esto funcionó bien con los navegadores ( Internet Explorer Internet Explorer & Netscape ). However I was still not satisfied. Sin embargo yo aún no estaba satisfecho. The external dependency was bugging me. La dependencia externa se me escucha. The next step was to try to execute javascript code within Java itself, using the same LiveConnect bridge. El siguiente paso fue tratar de ejecutar código JavaScript Java dentro de sí mismo, utilizando el mismo puente LiveConnect. My first attempt to set the size using Mi primer intento de fijar el tamaño usando JSObject.getMethod failed in IE. no en IE. Apparently Internet Explorer doesn’t support the method! Al parecer, Internet Explorer no es compatible con el método! Then I simply evaluated the whole code using eval. Entonces yo simplemente evaluado el código en su totalidad utilizando eval. This worked well for both the browsers. Esto funcionó bien para los navegadores. I could get rid of the pesky javascript method - resize. Podría deshacerse de los molestos javascript método - el tamaño. Now finally I was happy. Ahora que finalmente fue feliz. As I soon realized however there was still a little snag. Como pronto me di cuenta sin embargo todavía queda un poco engancharse. The fixes don’t work in Opera browser. Los parches no funcionan en el navegador Opera. But I am not too worried considering the market share of this browser. Pero no me preocupa demasiado teniendo en cuenta la cuota de mercado de este navegador.

To summarize the key line of code: jso.eval(applet + “width = ” + width + “;”); Para resumir las principales líneas de código: jso.eval (applet + "width =" + ancho + ";");