• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Making one function wait for another?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys


I am just trying to figure out the best way to make one function wait for another e.g



Given this code what would be the best way to make the second call to selectcues wait until the first call has run its course? Is there anyway to do this?


Thanks alot
 
Marshal
Posts: 27368
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way to do that would be to put them on consecutive lines inside one of the methods of your class. Just as you did in the example you posted. The JVM always executes statements sequentially if they are written that way.

 
Ramzi Hajaj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah i have done that but it does not produce the desired effect. The function that is being called produces a jframe object which requires user interaction. so essentially i get two jframes, instead of the desired one jframe, wait for interaction then the other jframe?

When creating a jframe object is a new thread of execution created?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, when creating a JFrame, the user interaction is performed in a different thread - the Event Dispatch Thread (also referred to as 'the GUI thread' sometimes). If you want to block the main thread from finishing (keep the first method from finishing and the second method from starting) you don't want to use a JFrame. You want to use a Modal dialog which blocks the triggering thread. I believe JOptionPane might work if you have relatively simple interaction with the user in mind.

If the interaction is not so simple your approach may be upside down. Instead of having the main thread dictate order by creating a GUI, blocking until the GUI is finished, then creating a new GUI, you might consider using the GUI as the driver to trigger settings/configuration and eventually, when required, to destroy or hide one JFrame and display a different one.
 
I am Arthur, King of the Britons. And this is a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic