| Java Spring 2006 - HW6 FAQ |
|   Java Prog Home   |   HW6 Assignment |
+ Do they have to press Enter in textfield?
|
Question: | Is it OK if our program assumes the user hits the Enter key after changing each text field? |
|
Answer: | Yes, although it's not difficult to receive events each time a change is made by the user (check out the DocumentListener interface). |
+ How do I get rid of the window and the GUI thread?
|
Question: | Once the user presses the done button, I want the window to disappear and the GUI thread to stop - how do I do this? |
|
Answer: | Call the NOte that you don't want to call dispose from within the GUI thread (so don't call it from your actionHandler!). |
+ How do I wait?
|
Question: | My edit() method is not supposed to return until the user presses the done button, how do I do this? |
|
Answer: | You need a loop that waits until the user has
pressed done (has indicated they are done changing the fields). You do something like this at the end of your while (done==false) {
}
Assuming the actionhandler for the button can set the variable done to true, this would work. However, this is bad because your thread will spend lots of CPU time going through the loop over and over (this is called busy waiting). The following would be much better: while (done==false) {
Thread.sleep(500);
}
This makes the loop take 500ms each time, so you won't be using up all the CPU. |