Stopping events of a Jbutton
Hi.
I have a program in which I have to count each click that a user do in a Frame, and with this information, I have to do a lot of things. The problem that I have is that I pass the number of clicks successfully to this class that manage an array, but in this class, when I try to use the number of clicks variable in another method in this same class, is set as 0. I guess that is something about the Frame itself, it have actionListeners on or something like that.
Can somebody help?
Regards.
[521 byte] By [
karma1234a] at [2007-11-27 3:54:55]

> I have a program in which I have to count each click
> that a user do in a Frame,
Do you mean click on a button in the frame ?
in that case you can increment the counter on the mousePressed Listner
>> and with this information,
> I have to do a lot of things. The problem that I have
> is that I pass the number of clicks successfully to
> this class that manage an array, but in this class,
> when I try to use the number of clicks variable in
> another method in this same class, is set as 0. I
> guess that is something about the Frame itself, it
> have actionListeners on or something like that.
>
Cant figure out what you are trying to achive ?
Please explain or post some code.
cheers
Ok
public void mousePressed(MouseEvent evento) {
this.dibujar(evento);
controlador.getCoordenadas(evento.getX(),evento.getY());
controlador.getClicks();
}
This is the code when the mousePressed is performed.
Then, I call this method in other class
public void crearDistanciaArreglo(){//
contadorDeClicks++;
System.out.println("va por "+contadorDeClicks+" Contador De Clicks");//
}
Finally, when I try to use the contadorDeClicks variable, it have 0 value,, but when I printed it in the method, it have the correct values...
Regards.
I am not sure what your objective is. But If you declare the contadorDeClicks variable as static, you will get the updated value.
> Ok
>
> > public void mousePressed(MouseEvent evento) {
>this.dibujar(evento);
> controlador.getCoordenadas(evento.getX(),evento.getY()
> );
>controlador.getClicks();
>
>
>
> This is the code when the mousePressed is performed.
>
> Then, I call this method in other class
>
> > public void crearDistanciaArreglo(){//
>contadorDeClicks++;
> System.out.println("va por "+contadorDeClicks+"
> Contador De Clicks");//
> }
>
> Finally, when I try to use the contadorDeClicks
> variable, it have 0 value,, but when I printed it in
> the method, it have the correct values...
>
> Regards.
If you want to count the number of clicks then put the counter inside the mousePressed listner
public void mousePressed(MouseEvent evento)
{
clickcounter++;
this.dibujar(evento);
controlador.getCoordenadas(evento.getX(),evento.getY() );
controlador.getClicks();
}
clickcounter is the counter which is incremented when the mouse is clicked.
The clickcounter is the varible of the frame class in which you want to count the clicks. you can pass this variable.
