aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes issue with returning from method or calling new object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "issue with returning from method or calling new object" Watch "issue with returning from method or calling new object" New topic
Author

issue with returning from method or calling new object

Keith Spriggs
Greenhorn

Joined: Jul 19, 2012
Posts: 18
Hi guys,
This problem has me absolutely stumped, and even a couple of people I have shown it to.
If I leave in an system.out.println statement given the current state of a boolean expression it will allow me to call another object which creates a frame.
If I take it out, then it doesn't call the next object.

Before, I go on I would like to apologise for the poor code, but it generally works.

This is the main method


This is the method is being called


If anybody could suggest any slightly better code I would appreciate it.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
these
while(myApp.getValidKeyPress() == false)
while(myApp.getIsStringFinished() == false)
are just terrible.

perhaps if you explained exactly what you're trying to achieve we might have better suggestions.
e.g. perhaps a modal dialog might be better if you're trying to get a name/id into your MyApplication class
Keith Spriggs
Greenhorn

Joined: Jul 19, 2012
Posts: 18
Thanks for the feedback.
I am the first to admit that the code is really brutal and it needs to be tidied up, big time.

The reason why I used the while loops is to get control from the key press. I found that without the while loops there would be no returns back from the called class. When I ran the program it skipped over waiting for a return from the called method which was a gui.
I know the correct method would be to use the invoke later and invoke and wait commands. However, I have been looking for examples in how to use these with called methods, but I haven't found an examples of this.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Those loops will run whenever either buttons is not enabled, and continue to run until the buttons are enabled.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
OK,but the question remains,
what are you trying to achieve?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

That just isn't the way to wait for a button press, or a key press, in a Swing program. So there's really no point in trying to make it work. It would be much better to just write an ordinary Swing application which does that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: issue with returning from method or calling new object