Resizing Applets from Java code - A second pass Cambiar el tamaño de applets de Java de código - Un segundo paso
Challenge: Resizing applet from within Java code. Desafío: Cambiar el tamaño de applet de Java en código. For example say the applet code calculates that the applet needs more space than it has been allocated, then how to go about it? Por ejemplo dicen que el código applet calcula que el applet necesita más espacio de lo que ha sido asignado, entonces cómo hacerlo?
Last time when faced with this problem La última vez cuando se enfrentan a este problema I solved it with a nifty piece of Javascript method I resolverse con una excelente pieza de Javascript método . However I soon realized there were few issues with the approach. Sin embargo pronto se dieron cuenta que había algunas cuestiones con el planteamiento.
First we made the applet dependent on external piece of Javascript method which creates undesirable dependency. En primer lugar hemos hecho el applet depende de la pieza externa de Javascript método que crea dependencia indeseable.
The main problem was when we wanted to embed multiple such applets in the same page. El principal problema fue cuando quisimos integrar múltiples tales applets en la misma página. Obviously now I cannot use the same resize method, which is hardcoded to call the applet by name. Es evidente que ahora no puedo utilizar el mismo tamaño de método, que es hardcoded llamar al applet por su nombre. Also I found that document['appletname'] logic fails when the applet is within a table. También me di cuenta de que el documento [ 'appletname'] lógica falla cuando el applet se encuentra dentro de una tabla. Then we have to refer to the applet using the hierarchy which we do not control. Entonces tenemos que hacer referencia a la applet utilizando la jerarquía que no controlamos. We also cannot have two applets with the same name as then only the first one executes. Tampoco podemos tener dos applets con el mismo nombre que entonces sólo el primero se ejecuta.
So it was obvious we needed to pass the name of the applet to this method. Por lo tanto, era obvio que necesitábamos para pasar el nombre del applet a este método. But how to get the name? Pero, ¿cómo obtener el nombre?
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. I intuited correctamente que, desde applet.getParameter usado para obtener los parámetros dentro de la etiqueta de applet, es posible que podamos obtener el nombre del applet utilizando el mismo método. That turned out to be the case. Que resultó ser el 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. Así que ahora he tenido esta versión que me pasó el nombre del applet al tamaño de método y el applet llamado por su nombre (applets [ 'nombre']) y establecer el tamaño, tal como fue aprobado por los parámetros. This worked fine with both the browsers ( Esto funcionó bien con los navegadores ( Internet Explorer Internet Explorer & Netscape ). However I was still not satisfied. Sin embargo yo aún no estaba satisfecho. The external dependency was bugging me. La dependencia externa se me escucha. The next step was to try to execute javascript code within Java itself, using the same LiveConnect bridge. El siguiente paso fue tratar de ejecutar código JavaScript Java dentro de sí mismo, utilizando el mismo puente LiveConnect. My first attempt to set the size using Mi primer intento de fijar el tamaño usando JSObject.getMethod failed in IE. no en IE. Apparently Internet Explorer doesn’t support the method! Al parecer, Internet Explorer no es compatible con el método! Then I simply evaluated the whole code using eval. Entonces yo simplemente evaluado el código en su totalidad utilizando eval. This worked well for both the browsers. Esto funcionó bien para los navegadores. I could get rid of the pesky javascript method - resize. Podría deshacerse de los molestos javascript método - el tamaño. Now finally I was happy. Ahora que finalmente fue feliz. As I soon realized however there was still a little snag. Como pronto me di cuenta sin embargo todavía queda un poco engancharse. The fixes don’t work in Opera browser. Los parches no funcionan en el navegador Opera. But I am not too worried considering the market share of this browser. Pero no me preocupa demasiado teniendo en cuenta la cuota de mercado de este navegador.
To summarize the key line of code: jso.eval(applet + “width = ” + width + “;”); Para resumir las principales líneas de código: jso.eval (applet + "width =" + ancho + ";");
Filed under Filed under Java Software El software de Java , Web | |
| |
RSS 2.0 RSS 2,0 | |
Email this Article Enviar artículo
You may also like to read También puede leer |





April 22nd, 2008 at 11:53 am 22 de abril de 2008 a 11:53 am
import java.awt.*; importar java.awt .*;
import java.awt.event.*; importación java.awt.event .*;
import javax.swing.*; importación javax.swing .*;
import javax.swing.JFileChooser; javax.swing.JFileChooser importación;
import java.io.*; importación java.io. *;
import javax.imageio.ImageIO; importación javax.imageio.ImageIO;
class SceneViewer2 extends JFrame implements MouseListener, MouseMotionListener SceneViewer2 clase se extiende JFrame implementa MouseListener, MouseMotionListener
{ (
JFrame jf=new JFrame(”Your created Scene”); JFrame jf = new JFrame ( "Tu Escena creado");
JPanel jp=new JPanel(); JPanel jp = new JPanel ();
private int xAdjustment; INT xAdjustment privado;
private int yAdjustment; INT yAdjustment privado;
Component dragComponent; Componente dragComponent;
public static void main(String args[]) public static void main (String args [])
{ (
new SceneViewer2(); nuevo SceneViewer2 ();
} )
SceneViewer2() SceneViewer2 ()
{ (
jf.setExtendedState (getExtendedState () | JFrame.MAXIMIZED_BOTH);//MAXIMIZES THE WINDOW ON EXECUTION jf.setExtendedState (getExtendedState () | JFrame.MAXIMIZED_BOTH); / / maximiza la ventana en ejecución
jp = (JPanel) jf.getContentPane (); jp = (JPanel) jf.getContentPane ();
jp.setLayout (null); jp.setLayout (null);
jp.addMouseListener( this ); jp.addMouseListener (este);
jp.addMouseMotionListener( this ); jp.addMouseMotionListener (este);
JLabel[] lblPic=new JLabel[2]; JLabel [] lblPic = new JLabel [2];
//inserts 1st image / / 1 ª inserta imagen
lblPic[0]=new JLabel(); lblPic [0] = new 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 = new ImageIcon ( "atif3.jpg");
Image sel=selected_image.getImage(); Imagen sel = selected_image.getImage ();
selected_image=new ImageIcon(sel.getScaledInstance(lblPic[0].getWidth(),lblPic[0].getHeight(),1)); selected_image = new 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 / / inserta 2 ª imagen
lblPic[1]=new JLabel(); lblPic [1] = new JLabel ();
lblPic[1].setBounds(300,0,200,200); lblPic [1]. setBounds (300,0,200,200);
selected_image=new ImageIcon(”ash3.jpg”); selected_image = new 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 = new 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 (true);
} )
//CODE FOR MOVING THE IMAGES ON DRAG / / Código para pasar las imágenes de arrastre
public void mousePressed(MouseEvent e) public void mousePressed (MouseEvent e)
{ (
Container container = (Container)e.getSource(); = Contenedor de contenedores (Container) e.getSource ();
Component component = container.findComponentAt(e.getX(), e.getY()); Componente componente = container.findComponentAt (e.getX (), e.getY ());
if (component instanceof JPanel) return; if (componente instanceof JPanel) regreso;
dragComponent = component; dragComponent = componente;
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) public void mouseDragged (MouseEvent e)
{ (
if (dragComponent == null) if (dragComponent == null)
return; retorno;
dragComponent.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment); dragComponent.setLocation (e.getX () + xAdjustment, e.getY () + yAdjustment);
} )
public void mouseReleased(MouseEvent e) public void mouseReleased (MouseEvent e)
{ (
dragComponent = null; dragComponent = null;
} )
public void mouseClicked(MouseEvent e) {} public void mouseClicked (MouseEvent e) ()
public void mouseMoved(MouseEvent e) {} public void mouseMoved (MouseEvent e) ()
public void mouseEntered(MouseEvent e) {} public void mouseEntered (MouseEvent e) ()
public void mouseExited(MouseEvent e) {} public void mouseExited (MouseEvent e) ()
} )
this is my proggrame…. esta es mi proggrame….
i want a resizing code so i can rezise the image also.. Quiero un cambio de tamaño de código para que pueda rezise también la imagen ..