I am trying to create an object multiple times, using a do-while loop, but the loop's test is executed before the object I have created has finished doing what it is supposed to be doing. I can see where this is failing. After the object's constructor is called, an instance of that object is created and the loop's test is performed. I want the loop's test to be performed after the user has entered some input into that object, not after the constructor method returns.
The following code illustrates my problem. This is, by the way, just a simplistic example that captures the part I am having trouble with. The program I am working on is more complicated. It should be noted that I can't edit the object related methods of the "Program" class; this is a problem that must be addressed from within the main method.
If anyone can shed some light into this I'd appreciate it.
I think what you're running into is the AWT / Swing event thread. Creating a window (JFrame) creates a new thread where button events and such take place. Your main thread does not wait for that one but goes merrily on its way.
You may need to make the main thread wait() on some object and do a notifyAll() on that object after reading the text. Any object will do. Maybe pass a String along to the program constructor and make sure it's available to the method that prompts for text.
I'm hedging my bets here because I don't do much Swing these days. Did that make sense? Check it out by displaying the thread name in main and in the event handler. [ March 17, 2007: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi