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私はそれを解決する気の利いた作品の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.また、 2つのアプレットをすることはできませんと同じ名前で入力し、最初の1つのみが実行されます。
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インターネットエクスプローラ & 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.は、次のステップを試しにJavaScriptのコードを実行するJava自体は、使用して、同じLiveConnectの橋です。 My first attempt to set the size using私の最初の試みが設定してサイズを使用して JSObject.getMethod jsobject.getmethod failed in 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.私が厄介な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.仕事での修正はありませんOperaブラウザです。 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 (アプレット+ "幅= " +幅+ ";");