Challenge: Resizing applet from within Java code. Sfida: Ridimensionare applet da codice Java. For example say the applet code calculates that the applet needs more space than it has been allocated, then how to go about it? Per esempio dire il codice applet calcola che l'applet richiede più spazio di quello che è stato assegnato, allora come procedere?

Last time when faced with this problem Ultima volta di fronte a questo problema I solved it with a nifty piece of Javascript method Ho risolto con un pezzo di nifty metodo Javascript . However I soon realized there were few issues with the approach. Tuttavia ho capito presto ci sono stati alcuni problemi con l'approccio.

First we made the applet dependent on external piece of Javascript method which creates undesirable dependency. In primo luogo abbiamo fatto l'applet dipende da esterno pezzo di Javascript metodo che crea dipendenza indesiderabili.

The main problem was when we wanted to embed multiple such applets in the same page. Il principale problema è stato quando abbiamo voluto incorporare più tali applet nella stessa pagina. Obviously now I cannot use the same resize method, which is hardcoded to call the applet by name. Ovviamente adesso non posso utilizzare lo stesso metodo di ridimensionamento, che è hardcoded di chiamare l'applet per nome. Also I found that document['appletname'] logic fails when the applet is within a table. Ho trovato anche questo documento [ 'appletname'] logica non quando l'applet è all'interno di una tabella. Then we have to refer to the applet using the hierarchy which we do not control. Quindi dobbiamo fare riferimento alla applet utilizzando la gerarchia che noi non controlliamo. We also cannot have two applets with the same name as then only the first one executes. Anche noi non può avere due applet con lo stesso nome come allora solo il primo esegue.
So it was obvious we needed to pass the name of the applet to this method. Così è stato evidente avevamo bisogno di passare il nome del applet a questo metodo. But how to get the name? Ma come ottenere il nome?
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. Ho intuito correttamente che, dal momento che applet.getParameter usato per ottenere i parametri dal di dentro l'applet tag, è possibile che siamo in grado di recuperare il nome del applet utilizzando lo stesso metodo. That turned out to be the case. Che si è rivelato essere il 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. Così ora ho avuto questa versione, dove ho passato il nome di l'applet a ridimensionare il metodo e ha invitato l'applet con il suo nome (applet [ 'name']) e impostare la dimensione come trasmesso dal parametri. This worked fine with both the browsers ( Questo lavorato bene con entrambi i browser ( Internet Explorer Internet Explorer & Netscape ). However I was still not satisfied. Tuttavia ero ancora non soddisfatte. The external dependency was bugging me. La dipendenza esterna è stata bugging me. The next step was to try to execute javascript code within Java itself, using the same LiveConnect bridge. Il passo successivo è stato quello di tentare di eseguire codice JavaScript all'interno di Java stesso, utilizzando lo stesso LiveConnect ponte. My first attempt to set the size using Il mio primo tentativo di impostare la dimensione utilizzando JSObject.getMethod failed in IE. non in IE. Apparently Internet Explorer doesn’t support the method! Apparentemente di Internet Explorer non supporta il metodo! Then I simply evaluated the whole code using eval. Poi ho semplicemente valutato l'intero codice utilizzando eval. This worked well for both the browsers. Questo ha funzionato bene, sia per il browser. I could get rid of the pesky javascript method - resize. Ho potuto sbarazzarsi di pesky il metodo javascript - ridimensionare. Now finally I was happy. Ora finalmente ero felice. As I soon realized however there was still a little snag. Come ho realizzato presto tuttavia si è ancora un po 'intoppo. The fixes don’t work in Opera browser. Le correzioni non funzionano nel browser Opera. But I am not too worried considering the market share of this browser. Ma non sono troppo preoccupati considerando la quota di mercato di questo browser.

To summarize the key line of code: jso.eval(applet + “width = ” + width + “;”); Per riassumere la chiave riga di codice: jso.eval (applet + "width =" + larghezza + ";");