Resizing Applets from Java code - A second pass الحجم بريمجات جافا من قانون -- ثانية تمر
Challenge: Resizing applet from within Java code. التحدي : برنامج صغير الحجم من داخل جافا المدونه. 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 قطعة من طريقة جافا سكريبت . 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. اولا جعلنا بريمج الخارجية التي تعتمد على قطعة من طريقة جافا سكريبت غير مرغوب فيه مما يؤدي الى التبعيه.
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. ومن الواضح الآن لا استطيع تغيير حجم استخدام نفس الأسلوب ، وهو hardcoded لدعوة بريمج بالاسم. 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. صحيح انني محدوس 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. كانت الخطوة التالية هي محاولة لتنفيذ قانون جافا سكريبت داخل جافا نفسها ، باستخدام نفس liveconnect الجسر. My first attempt to set the size using اول محاولة لتحديد حجم استخدام JSObject.getMethod Jsobject.getmethod failed in IE. في اي فشل. Apparently Internet Explorer doesn’t support the method! ويبدو ان انترنت اكسبلورر لا يدعم هذه الطريقة! Then I simply evaluated the whole code using eval. ثم انني ببساطة تقييم كامل باستخدام قانون مييقتلا هدحو. This worked well for both the browsers. هذا بشكل جيد على حد سواء المتصفحات. I could get rid of the pesky javascript method - resize. انا يمكن التخلص من جافا سكريبت طريقة pesky -- تغيير. 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 (بريمج + "العرض =" + العرض + "؛")؛
Filed under المقدم بمقتضى Java Software برنامج جافا , ، Web شبكة | |
| |
RSS 2.0 ار اس اس 2،0 | |
Email this Article ارسل هذه المادة
You may also like to read ويمكنك ايضا ان تقرأ |





April 22nd, 2008 at 11:53 am نيسان / ابريل 22nd ، 2008 في الساعة 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 الطبقة sceneviewer2 تمتد jframe تنفذ mouselistener ، mousemotionlistener
{ (
JFrame jf=new JFrame(”Your created Scene”); Jframe JF = jframe جديدة) "الخاصة بك انشاء مسرح") ؛
JPanel jp=new JPanel(); Jpanel ج ب = jpanel الجديدة () ؛
private int xAdjustment; xadjustment الخاص دولي ؛
private int yAdjustment; 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 (); ج ب = (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 / / تدرج الصورة الاولى
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(); صورة selected_image.getimage sel = () ؛
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 / / تدرج الصورة الثانية
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; اذا كانت الاجابه ب (العنصر instanceof 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 الصورة ايضا..