Challenge: Resizing applet from within Java code. Проблема: Изменение размера апплет из 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? К примеру сказать, апплет код рассчитывает, что апплет нужно больше места, чем она была выделена, то каким образом сделать это?

Last time when faced with this problem Последний раз, когда сталкиваются с этой проблемой I solved it with a nifty piece of Javascript method Я решить ее с nifty кусок Javascript метод . 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. Сначала мы сделали апплет зависит от внешних кусок Javascript метод, который создает нежелательные зависимости.

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. Кроме того, я обнаружил, что в документе [ 'appletname'], не логика, когда апплет находится в таблице. 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. Я intuited правильно, что, поскольку applet.getParameter используется для получения параметров внутри тега апплета, возможно, что мы можем извлечь название апплет, используя тот же метод. 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 Internet Explorer & И Netscape ). However I was still not satisfied. Однако я по-прежнему не удовлетворены. The external dependency was bugging me. Внешняя зависимость была bugging меня. The next step was to try to execute javascript code within Java itself, using the same LiveConnect bridge. Следующий шаг состоит в том, чтобы попытаться выполнить javascript код в Java сам, используя тот же LiveConnect моста. My first attempt to set the size using Мои первые попытки установить размеры с помощью JSObject.getMethod failed in IE. неудачу в IE. Apparently Internet Explorer doesn’t support the method! Видимо Internet Explorer не поддерживает метод! Then I simply evaluated the whole code using eval. Тогда я просто оценить весь код с помощью eval. This worked well for both the browsers. Это хорошо для обоих браузеров. I could get rid of the pesky javascript method - resize. Я мог бы избавиться от pesky javascript метод - размер. 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 + “;”); Подводя итог ключевых строку кода: jso.eval (апплет + "ширина =" + ширина + ";");