calls the doSomeMethod() when the NEW option is selected. However the Menu does not close till doSomeMethod() completes.
This is slightly annoying in my situation sine doSomeMethod() will take several seconds or more to complete(program is thinking bestmove), and the GUI looks awquard with the menu just hanging there while program thinks of move to play.
Is there anyway to close this menu first, before calling the doSomeMethod() method.
Thanks so much, you are amazing at this GUI stuff. I am allergic to threads, so this would have taken me months/years to figure out. I just ran the program, and it works great. I'm just reading through it all step by step, so I understand it properly
I'll let you know if I theres something I don't understand.
Thanks again for your time and effort
Joined: Apr 11, 2005
Ok, I understand it, except for:
Is the synchronized necessary, can you explain briefly its purpose?
Joined: Jan 14, 2004
The "synchronized" key word and its use are discussed in Threads: Doing Two or More Tasks at Once which is linked from How to Use Threads in the swing tutorial. This second page contains a brief discussion of "The Event-Dispatching Thread". In the test app the calculateNextMove method can be called multiple times by clicking on one or both of the menu items while the method thread is running. To observe this try running the app with and without the "synchronized" modifier. Without the modifier things get more chaotic. Using the "synchronized" modifier makes it where the method can be used by only one caller at a time. Others must wait in line until the current caller releases its lock on the method; then the next in line can lock the method and use it. It's a way to schedule calls to the method.