I'm doing a game of finding partners and a problem has arisen that I have not known for hours because it happens, I have the feeling that it will be silly but I can not see it. I mention the problem, I launch a method that should update the graphics of a button and if I do not meet a condition in a later method is restored, the thing is that I do not update the graphics . I detail:
1) When I press a key, I launch the method click on the button (), which changes the image that initially has the button by which it is supposed to be behind, the one that contains the object "Box". Then perform a rotation and send the object box to another method, compare Charts ().
private void pulsaCasilla(ActionEvent event)
{
Button obj = (Button)event.getSource();
for(Casilla c:casillas)
{
if(c.getButton().getId() == obj.getId())
{
String path = c.getRuta();
URL linkImg = getClass().getResource(path);
System.out.println("RUTA IMG : " + c.getRuta());
System.out.println(linkImg.toString());
Image img = new Image(linkImg.toString() , ancho, alto, false, true);
c.getButton().setGraphic(new ImageView(img));
System.out.println(c.getButton().getId());
System.out.println(obj.getId());
System.out.println("ENTRA");
RotateTransition rotarBoton = new RotateTransition(Duration.seconds(1) , c.getButton());
rotarBoton.setAxis(new Point3D(0,1,0));
rotarBoton.setFromAngle(0);
rotarBoton.setToAngle(360);
System.out.println("Inicia rotación");
rotarBoton.play();
comparaCasillas(c);
return;
}
}
}
2) The compareCasillas () method adds the "Squares" to an arrayList and when the arrayList has 2 stored it treats them. If the name is the same, I change the value of some labels to store the marker. If it is not the same, it resets both the start image. Then clean the arrayList.
private void comparaCasillas (Casilla c)
{
String name1 ="";
String name2 ="";
comparador.add(c);
c.getButton().setDisable(true);
if(comparador.size()==2)
{
System.out.println("Entra en el comparador");
name1 = comparador.get(0).getName();
name2 = comparador.get(1).getName();
if(name1.equalsIgnoreCase(name2))
{
System.out.println("Se ha producido un acierto");
//Restamos descubiertas y añadimos cubiertas.
descubiertas ++;
cubiertas --;
lv_Cubiertas.setText(""+cubiertas);
lv_Descubiertas.setText(""+descubiertas);
}
if(!name1.equalsIgnoreCase(name2))
{
System.out.println("Has fallado");
comparador.get(0).getButton().setDisable(false);
comparador.get(1).getButton().setDisable(false);
System.out.println("Ejecuta el poner las imagenes a la anterior");
imagenInicio(comparador.get(0).getButton());
imagenInicio(comparador.get(1).getButton());
}
movimientos ++;
lv_movimientos.setText(""+movimientos);
System.out.println("//////////////////////");
comparador.clear();
}
}
The problem I have is the following , when I make the first click on a button I change the image without problems and follow the normal course. But when I click on the second one it does everything except the change of image, the route passes well, but it is as if I solved the "false" directly, but I tried to place a Thread.sleep () before calling the stable method the initial image and nothing. In addition, the console output of the prints that I have placed follows the course ...