1

Como puedo conseguir el clic del usuario en ese array si ya tengo la ubicacion de todos los botones

Timer timer3 = new Timer(2000, new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
    {   
        int x= 0,y=0;
        for (int i=0;i<16;i++)
    
        {   
        x = btn_boton[i].getLocation().x;
                y = btn_boton[i].getLocation().y;
                btn_boton[i].setLocation(x,y+tmp);
                System.out.println("   i= "+ i +" " +" x= "+ x + " " + " y= "+ y);
           
        }
                
    }
       });
;


btn_boton = new JButton[16];
        for (int i=0;i<16;i++)
        {   
            btn_boton[i] = new JButton(String.valueOf(i+1));
            btn_boton[i].setBounds(80+60*(i%4),70+60*(i/4),50,50);  
                        ventana.add(btn_boton[i]);
        };

No logro mover un solo boton de el arreglo, y al ser un puzzle 15 necesito mover el boton que esta siendo tocado al espacio vacio solo si el espacio vacio esta a derecha izquierda arriba o abajo

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.