nt.KeyListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferStrategy; import javax.swing.*; public class Ventana extends Canvas { public final int ANCHO = 600; public final int ALTO = 730; public int ANpanel=ANCHO-5; public int ALpanel=ALTO; public BufferStrategy strategy; Pelota p; int ancho; int alto; public static void main(String[] args) { new Ventana(); } public Ventana() { JFrame ventana = new JFrame("...LABERINTO..."); ventana.setBounds(0,0,ANCHO,ALTO); ventana.setLocation (10,10); JPanel panel = (JPanel)ventana.getContentPane(); panel.setPreferredSize(new Dimension(ANpanel,ALpanel)); setBounds(0,0,ANpanel,ALpanel); panel.setLayout(null); panel.add(this); panel.setBackground(Color.darkGray); ventana.setVisible(true); ventana.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); ventana.setResizable(false); createBufferStrategy(2); strategy = getBufferStrategy(); requestFocus(); // addKeyListener(this); Pelota pelotaRoja = new Pelota(ancho, alto); pelotaRoja.start(); } public void paintComponent () { System.out.println("dentro de paint "); Graphics g = strategy.getDrawGraphics(); g.setColor(getBackground()); g.fillRect(0,0,ANpanel,ALpanel); g.setColor(Color.red); g.fillOval(12, 12,12, 12); strategy.show(); } } ************************************************************************************************************* CLASE PELOTA public class Pelota extends Thread { Ventana v; int ancho; int alto; int posX=10; int posY=10; int vX=1; int vY=2; public Pelota (int ancho, int alto) { this.ancho = ancho; this.alto = alto; } public void run() { while(true) { // detectarcolision(); mover(); System.out.println("llamo al game "); game(); try { Thread.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); } } } public void detectarcolision() { if ((posX<0)||(posX>v.ANpanel-ancho)) { vX=-vX; } } public void mover() { posX = posX + vX; } public void game() { System.out.println("llamo al paint "); v.repaint(); } }