jbutton and mouseEvent question

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:

  1. User presses button.
  2. User clicks somewhere else on screen
  3. Some code executes, doing something at the position where the second click occurred.

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();
      }
}