File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program goes past where I think it should wait for Return from called program

 
Will Barbee
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a greenhorn question but it is about Swing.

I have a program which is processing and has an error message to display
so it calls a message-display program (so all messages look alike in the application).
The calling program is editing data entered into a JTextField and the processing is
occurring in the actionPerformed area.

I have Focus Listeners on the JTextFields and am processing a selectAll() statement when a
field is focussed on. Also, in the fields in question in this test, I have added a println "Focus Gained jtfieldname".

During execution, the calling program continues on past the message program call even though
the message program has not issued a return. It seems to me that the calling program should wait
for the called message program to complete before continuing on.

The calling program has the following code:


And the message program has the following code to display after the after the
JLabels are defined.



When I run the application and cause the error condition, the following message sequence prints:



At this point, I have not clicked on the Return button in the message program.
But the calling program has continued processing.

After I click on the Return button in the message JFrame, the println displays:


Why does the calling program not wait for the Return button to be pressed in the message program
before continuing on in its processing?

 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since Swing is an event-driven library, what you are describing is normal expected behavior. Don't you want to show a modal JDialog here, not a JFrame? The modal dialog will block program flow until it is dealt with.

For example, a runnable demo program:
 
Will Barbee
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Pete.
I think I understand it.
I'll give it a test.
 
Will Barbee
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LESSON LEARNED:

Pete's program is quite instructive. It shows quickly how the Java processing works.

SO I modified the message program to use JDialog and all is well.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic