Med
asked on
Re: Mouse click/double click effect
Hi,
Hi there,
I want to use themultiple mouse clicks using my program. If I click an object once for the first time, it should print "Print # 1" and second time "Print # 2" and so on.
But every time it is printing "Print # 1". My piece of code is below.
If anybody can help.
Thanks in advance.
Med
-------
public void Method {
int click = 0;
if (click == 0) {
System.out.println("Print # 1");
click++;
}
else if (click == 1) {
System.out.println("Print # 2");
click++;
}
}
Hi there,
I want to use themultiple mouse clicks using my program. If I click an object once for the first time, it should print "Print # 1" and second time "Print # 2" and so on.
But every time it is printing "Print # 1". My piece of code is below.
If anybody can help.
Thanks in advance.
Med
-------
public void Method {
int click = 0;
if (click == 0) {
System.out.println("Print # 1");
click++;
}
else if (click == 1) {
System.out.println("Print # 2");
click++;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes. That will work from time to time. Problem with JDK (from Sun) that there is long time bug - mouseClicked doesnt work each time, when you actually click mouse button.
use mousePressed instead :) That will do it.
use mousePressed instead :) That will do it.
int click = 0;
if (click == 0) {
.....
'click' is local variable that is initialized every time when Method is called. use some 'external' variable / object field.
int click = 0;
public void Method {
if (click == 0) {
.....