Evan8
04-08-2002, 01:04 PM
Hi all,
I have a question about waiting without busy waiting. I'm trying to create a small popup window to prompt the user for some information, and i'm wondering how to write one that will wait for the user to take some action without eating up all of the cpu cycles. In this way, i can create one of these in another part of my code, and have that code stop until the user is done entering his info.
A good example of this is the Java object JFileChooser. Example code from the Sun site looks like:
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
You can see that the function "showOpenDialog()" somehow waits for the user to do something (click ok, or cancel), and returns a value after that. How is this done without busy waiting and taking up all the processing time?
Thanks very much!
-Evan
I have a question about waiting without busy waiting. I'm trying to create a small popup window to prompt the user for some information, and i'm wondering how to write one that will wait for the user to take some action without eating up all of the cpu cycles. In this way, i can create one of these in another part of my code, and have that code stop until the user is done entering his info.
A good example of this is the Java object JFileChooser. Example code from the Sun site looks like:
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
You can see that the function "showOpenDialog()" somehow waits for the user to do something (click ok, or cancel), and returns a value after that. How is this done without busy waiting and taking up all the processing time?
Thanks very much!
-Evan