• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

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

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Pete.
I think I understand it.
I'll give it a test.
 
Will Barbee
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic