Resizing Applets from Java code - A second passリサイズアプレットからJavaコード-2番目のパス
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 (アプレット+ "幅= " +幅+ ";");
Filed under提出されて Java Software Javaソフトウェア , 、 Webウェブ | |
| |
RSS 2.0 RSS 2.0を | |
Email this Article電子メールこの記事
You may also like to readを読むようにすることも可能 |




April 22nd, 2008 at 11:53 am 2008年4月22日11:53アム
import java.awt.*;インポートjava.awt .* ;
import java.awt.event.*;インポートjava.awt.event .* ;
import javax.swing.*;インポートjavax.swing .* ;
import javax.swing.JFileChooser;インポートjavax.swing.jfilechooser ;
import java.io.*;インポートjava.io. * ;
import javax.imageio.ImageIO;インポートjavax.imageio.imageio ;
class SceneViewer2 extends JFrame implements MouseListener, MouseMotionListener jframe実装クラスsceneviewer2拡張mouselistener 、 mousemotionlistener
{ (
JFrame jf=new JFrame(”Your created Scene”);新しいjframe jf = jframe ( "して作成したシーン" ) ;
JPanel jp=new JPanel();新しいjpanel jp = jpanel ( ) ;
private int xAdjustment;民間int xadjustment ;
private int yAdjustment;民間int yadjustment ;
Component dragComponent;コンポーネントdragcomponent ;
public static void main(String args[])公共の静的な無効メイン(文字列args [ ] )
{ (
new SceneViewer2();新しいsceneviewer2 ( ) ;
} )
SceneViewer2() sceneviewer2 ( )
{ (
jf.setExtendedState (getExtendedState () | JFrame.MAXIMIZED_BOTH);//MAXIMIZES THE WINDOW ON EXECUTION jf.setextendedstate ( getextendedstate ( ) | jframe.maximized_both ) ; / /ウィンドウを最大化する実行
jp = (JPanel) jf.getContentPane (); jp = ( jpanel ) jf.getcontentpane ( ) ;
jp.setLayout (null); jp.setlayout (ヌル) ;
jp.addMouseListener( this ); jp.addmouselistener (この) ;
jp.addMouseMotionListener( this ); jp.addmousemotionlistener (この) ;
JLabel[] lblPic=new JLabel[2]; jlabel [ ] lblpic =新しいjlabel [ 2 ] ;
//inserts 1st image / / 1日の画像を挿入
lblPic[0]=new JLabel(); lblpic [ 0 ] =新しいjlabel ( ) ;
lblPic[0].setBounds(0,0,200,200); lblpic [ 0 ] 。 setbounds ( 0,0,200,200 ) ;
ImageIcon selected_image=new ImageIcon(”atif3.jpg”);新しいimageicon selected_image = imageicon ( " atif3.jpg " ) ;
Image sel=selected_image.getImage();画像によるsel = selected_image.getimage ( ) ;
selected_image=new ImageIcon(sel.getScaledInstance(lblPic[0].getWidth(),lblPic[0].getHeight(),1));新しいselected_image = imageicon ( sel.getscaledinstance ( lblpic [ 0 ] 。 getwidth ( ) 、 lblpic [ 0 ] 。 getheight ( ) 、 1 ) ) ;
lblPic[0].setIcon(selected_image); lblpic [ 0 ] 。 seticon ( selected_image ) ;
jp.add(lblPic[0]); jp.add ( lblpic [ 0 ] ) ;
//inserts 2nd image / /第2の画像を挿入
lblPic[1]=new JLabel(); lblpic [ 1 ] =新しいjlabel ( ) ;
lblPic[1].setBounds(300,0,200,200); lblpic [ 1 ] 。 setbounds ( 300,0,200,200 ) ;
selected_image=new ImageIcon(”ash3.jpg”);新しいselected_image = imageicon ( " ash3.jpg " ) ;
sel=selected_image.getImage();なSEL = selected_image.getimage ( ) ;
selected_image=new ImageIcon(sel.getScaledInstance(lblPic[1].getWidth(),lblPic[1].getHeight(),1));新しいselected_image = imageicon ( sel.getscaledinstance ( lblpic [ 1 ] 。 getwidth ( ) 、 lblpic [ 1 ] 。 getheight ( ) 、 1 ) ) ;
lblPic[1].setIcon(selected_image); lblpic [ 1 ] 。 seticon ( selected_image ) ;
jp.add(lblPic[1]); jp.add ( lblpic [ 1 ] ) ;
jp.repaint(); jp.repaint ( ) ;
jf.setVisible(true); jf.setvisible (真の) ;
} )
//CODE FOR MOVING THE IMAGES ON DRAG / /のコードを移動して画像をドラッグ
public void mousePressed(MouseEvent e)公共無効mousepressed ( mouseeventメール)
{ (
Container container = (Container)e.getSource();コンテナコンテナ= (コンテナ) e.getsource ( ) ;
Component component = container.findComponentAt(e.getX(), e.getY());コンポーネントのコンポーネント= container.findcomponentat ( e.getx ( ) 、 e.gety ( ) ) ;
if (component instanceof JPanel) return;もし(コンポーネントのインスタンスをjpanel )を返します;
dragComponent = component; dragcomponent =コンポーネント;
xAdjustment = dragComponent.getLocation().x - e.getX(); xadjustment = dragcomponent.getlocation ( )を選ぶx -e .getx( ) ;
yAdjustment = dragComponent.getLocation().y - e.getY(); yadjustment = dragcomponent.getlocation ( )にY -e .gety( ) ;
} )
public void mouseDragged(MouseEvent e)公共無効mousedragged ( mouseeventメール)
{ (
if (dragComponent == null)もし( dragcomponent ==ヌル)
return;戻り;
dragComponent.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment); dragcomponent.setlocation ( e.getx ( ) + xadjustment 、 e.gety ( ) + yadjustment ) ;
} )
public void mouseReleased(MouseEvent e)公共無効mousereleased ( mouseeventメール)
{ (
dragComponent = null; dragcomponent =ヌル;
} )
public void mouseClicked(MouseEvent e) {}公共無効mouseclicked ( mouseeventメール) ( ( ) )
public void mouseMoved(MouseEvent e) {}公共無効mousemoved ( mouseeventメール) ( ( ) )
public void mouseEntered(MouseEvent e) {}公共無効mouseentered ( mouseeventメール) ( ( ) )
public void mouseExited(MouseEvent e) {}公共無効mouseexited ( mouseeventメール) ( ( ) )
} )
this is my proggrame….これは私のproggrame … 。
i want a resizing code so i can rezise the image also..コードのサイズを変更したいので、私はreziseのイメージも..