*I'm using Java.
I have this thread, agent, that explores a room to determine its size and clean it if it's dirty. Then I have the interface, which draws the agent as it explores the environment. Agent is subclassed from Thread, and Java takes care of managing the threads. All I do is create the thread and say object.start().
This works very well under normal circustances. However, the menus are enabled during this time, and that means the user can mess with the room while the agent is exploring it. That shouldn't happen.
So, once the user clicks the option that tells the agent to clean the room, I'd like to disable all the menus. Except this isn't working as it should. Here's the problem:
...
public void ActionPerformed(ActionEvent e)
{
//disable the menus with setEnabled(false);
agent.start();
//enable the menus with setEnabled(true);
}
The problem is that the menus are enabled before the agent thread executes its function. I thought about using Thread.join() - that would garantee that the code to enable the menus is only executed after the agent thread ends. But, if I use Thread.join() the interface doesn't update itself while the agent is moving, because it's waiting for the agent to finish!
I've thought about disabling the interface from the agent and then enabling it once the agent is done, but I'm not sure that would work and the biggest problem here is that the agent shouldn't be messing around with the menus.
So, to sum it up, I need a thread executing to update the interface/draw the agent moving, but that thread cannot be the same that enables the menu. It seems currently there is one thread doing both. Assuming that's possible and not too complicated.