GUI program locking up...  
Author Message
prolifekilledmywife@yahoo.com





PostPosted: 2005-12-29 5:16:00 Top

java-programmer, GUI program locking up... I'm using Netbeans 5.0 beta for an IDE, with swing components. The
situation is something like this:

The program is a board game - the user chooses a building from a panel,
and then is supposed to get a message to choose what resource to pay
for it with. Here's a trace of the code:

Game (main object):
....
board[i].activate():
Game.game.setPlayer(worker);
Game.game.playerMessage("Choose a wooden building
from the building panel.");
Game.game.waitForBuild(type) :
built = false;
state = type + Game.BuildWood -
1;

mainPanel.buildings.getBP().setSelectedIndex(type-1);
while(!built)
{ Thread.yield(); }
No problems yet. This works fine, unless a building that needs to call
chooseResource is selected.
So, the user clicks one of these buildings, which activates the
following code, which is where the freeze occurs:

String r = Game.game.chooseResource():
state = Game.chooseResource;
resource = "";
while(resource.length()==0)
Thread.yield();
return resource;

Now chooseResource does work in any other context - resource gets set
by a mouseClicked event handler in a panel out there. But at this
point, the GUI stops responding. The playerMessage never gets printed,
and the click event never gets triggered. I did some investigating,
printing out numbers inside the two inmost loops, and the
chooseResource loop is continually running. I know the code's ugly,
but even so, the cause of this behavior is beyond me. Any suggestions
would be greatly appreciated!

 
Chris Smith





PostPosted: 2005-12-29 8:16:00 Top

java-programmer >> GUI program locking up... email***@***.com <email***@***.com> wrote:
> I'm using Netbeans 5.0 beta for an IDE, with swing components. The
> situation is something like this:

[...]

Please don't multipost. I just wrote you an answer in a different
newsgroup.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation