I have a problem, what happens is that I have a button in my Frame, that button changes the text when it is executed, the idea is that when the user finds the object, he changes the name of the button and so, and additional of a limit of clicks, in this case it gives me but it gives 11 click limits or more I do not understand because if I have predefined turns == 2 and it should give only two opportunities to click to look for the image.
public class Bosque extends javax.swing.JFrame {
private boolean estado;
private int contar;
private String nombre;
private int indicador;
private int turnos;
ArrayList<String> datos = new ArrayList<String>();
public Bosque() {
initComponents();
}
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
Niveles ni = new Niveles();
ni.setVisible(true);
this.dispose();
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
estado = false;
Inicio();
}
private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
estado = true;
Inicio();
jButton3.setVisible(false);
datos.add("Arrebal");
datos.add("Acemila");
datos.add("Afilo");
datos.add("Agave");
datos.add("Ajaraca");
datos.add("Alcatifa");
datos.add("Amanal");
datos.add("Bajel");
datos.add("Espuela");
datos.add("Rapa");
datos.add("Servillana");
indicador = 1;
jButton1.setText(datos.get(indicador));
turnos=0;
}
private void arrebolMouseClicked(java.awt.event.MouseEvent evt) {
if (jButton1.getText().equals("Arrebol")) {
arrebol.setVisible(false);
nombre = "Arrebol";
CleanBoton();
contar += 1;
puntaje.setText("puntos: "+contar);
indicador += 1;
jButton1.setText(datos.get(indicador));
}else{
turnos++;
if(turnos==2){
JOptionPane.showMessageDialog(null, "Perdite el nivel hiciste mas intentos de los debidos", "Perdiendo",JOptionPane.INFORMATION_MESSAGE);
this.dispose();
}
}
}
private void Inicio() {
acemila.setVisible(estado);
afilo.setVisible(estado);
agave.setVisible(estado);
ajaraca.setVisible(estado);
alcatifa.setVisible(estado);
amanal.setVisible(estado);
arrebol.setVisible(estado);
ave.setVisible(estado);
bajel.setVisible(estado);
cabana.setVisible(estado);
canasta.setVisible(estado);
caperuza.setVisible(estado);
cortaarbol.setVisible(estado);
espuela.setVisible(estado);
hongo.setVisible(estado);
jarron.setVisible(estado);
lena.setVisible(estado);
lobo.setVisible(estado);
rapa.setVisible(estado);
servillana.setVisible(estado);
tink.setVisible(estado);
guardabosques.setVisible(estado);
panda.setVisible(estado);
lena.setVisible(estado);
jButton1.setVisible(estado);
}