Is this a valid strategy?
I've got a client object that calls a JFrame from a separate view object. The view object accepts user input via textfields, radiobuttons and the like. I've tried to keep the view object as dumb as possible, so it only has to draw the JFrame. The client object therefore has to wait until the user hits the 'run' or 'cancel' buttons in the view object.
Using the While loop, the client code is something like...
UI_JFrame frame = new UI_JFrame();
//Set up frame and show for user input
frame.setUpAndShow();
//Wait for user input
while (frame.getRunOrCancelButtonsWereClicked() == false){
}
//Get input
frame.getUserInputValues();
//Proceed with stuff...
The UI_JFrame object includes an actionListener on the appropriate buttons which sets the return of getRunOrCancelButtonsWereClicked() to True.
At present I have done UI_JFrame extends JDialog, which seemed like a good idea from the literature that I read, though I don't fully understand why.
I've unsuccessfully tried wait/notify, but the problems I have had relate to who owns the thread. I think part of the issue is that I want the client object to wait on the view object, but the view object operates on a separate thread.
I have also tried JOptionDialog, but its unsuitable for the functions I want for user input (in particular, disabling the 'run' button until the user input meets certain criteria).
The only issue with the While loop is that it polls the view object many thousands of times per second. Is this a problem? I guess I could slow down the polling by implementing a ClockListener (which will include a wait/notify mechanism) to poll every few milliseconds, but it seems like a klunky solution.
If there is a better way to do it please let me know, but is the While loop stratgey a valid approach?