hi,
i want to know if its possible to have a Jbutton wait for a mouse click before executing its code.
i want to draw sth at the position of the mouse click but only after i press this button…
hi,
i want to know if its possible to have a Jbutton wait for a mouse click before executing its code.
i want to draw sth at the position of the mouse click but only after i press this button…
It sound like your use case is:
Is this right?
In this case, I don’t think you want to “execute the code of the JButton” at a later time.
What you actually want to do is have some code execute in response to a mouse event, but only if the button has been pressed immediately before.
Is this an accurate description?
Perhaps you could try explaining what you are REALLY trying to do - i.e. what the user is doing, not what the buttons and your code are doing - and I can explain how I would approach it.
make the function of the button be:
waitingForClicks = true;
clickCount = 0;
In your mouseClick method, do:
if (waitingForClicks) {
clickCount++;
if (clickCount == s) {
doStuff();
}
}