Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I have a problem creating this object multiple times (thanks to some Listener)

 
Clark Johnson
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Craig Wood
Ranch Hand
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The call to showDialog is hidden inside the buttons ActionListener.
So you have to find a way to fire an ActionEvent for the button.
Testing for String equality works better with the equals method.
 
Clark Johnson
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Testing for String equality works better with the equals method."

I know, but that's not my problem.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic