I try that a image to move with a cursors and i would to get to pass something like a focus that another image to move with a cursors next to move with a cursors the first image. Now I only have got to move simultaneus the two images but i would like to move independently each image. What i can do? Thanks This is the code that I get with the two images.
import java.awt.Frame; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.net.MalformedURLException; import java.net.URL; import javax.swing.ImageIcon; public class Ejemplo extends Frame implements KeyListener { private static final long serialVersionUID = 1L; private String imageURL = "http://dreamers.com/byrne/46.jpg"; private ImageIcon imagen; private ImageIcon imagen1; private int x; private int y; public int x1; public int y1; public static void main(String[] paramArrayOfString) { Ejemplo localEjemplo = new Ejemplo(); localEjemplo.setVisible(true); } Ejemplo() { super("Ejemplo"); setSize(500, 500); this.x = 200; this.y = 200; this.x1 = (this.x + 300); this.y1 = this.y; try { this.imagen = new ImageIcon(new URL(this.imageURL)); } catch (MalformedURLException localMalformedURLException1) { localMalformedURLException1.printStackTrace(); } try { this.imagen1 = new ImageIcon(new URL(this.imageURL)); } catch (MalformedURLException localMalformedURLException2) { localMalformedURLException2.printStackTrace(); } addKeyListener(this); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent paramWindowEvent) { System.exit(0); } }); } public void keyPressed(KeyEvent paramKeyEvent) { int i = 1; int j = 1; switch (paramKeyEvent.getKeyCode()) { case 38: this.y -= 1; break; case 40: this.y += 1; break; case 37: this.x -= 1; break; case 39: this.x += 1; break; default: i = 0; } if (i != 0) { repaint(); } public void paint(Graphics paramGraphics) { if (this.imagen != null) { paramGraphics.drawImage(this.imagen.getImage(), this.x, this.y, this.imagen.getImageObserver()); paramGraphics.drawImage(this.imagen1.getImage(), this.x1, this.y1, this.imagen1.getImageObserver()); } else { paramGraphics.drawString("Can't load image " + this.imageURL, this.x, this.y); paramGraphics.drawString("Can't load image " + this.imageURL, this.x1, this.y1); } } public void keyReleased(KeyEvent paramKeyEvent) { } public void keyTyped(KeyEvent paramKeyEvent) { } }