Using a while loop to wait for mouse click -> inefficient?
I am still in the design portion of a program I want to make for fun, and am brainstorming how to handle a certain aspect, waiting for a mouseclick.
Basically, I want the user to be able to enter a value, hit enter or a button, then click on a panel in a certain area, and I want both the value and the mouse click event to go to a certain method.
It's obviously easy to pass the value (most likely in a JTextField) to the method, but associating a mouseclick with it too is what's getting me.
One way I though of doing it is with a method that returns the next mouse event. It would have some instance variable, a mouseClick event, that is made null. Then when the mouse listener picks up on something, set the mouse event to that. If I did this, how would this while statement work?
Basically I want the while to loop and loop until a mouse event is recorded. Is this a good way to do this? Would it cause trouble / a lot of cycles or just 1 since it's not seeing mouseEvent1 changing?
while (mouseEvent1 == null)
I know this is a pretty abstract question and I could try it out now, but I'm not sure if I'll be able to detect the poor style of this approach.
Thanks very much!