A question for any Java gurus out there.
I’m working on a full screen Java game that basically blows off all the Java controls and panels and such. I use double buffered 2D graphics (using AWT), and my own library for implementing windows, buttons, and the like.
But I’m stuck on how to do modal dialogs. In C/C++, I do it like this
Normal Loop:
while (true)
{
update
draw
}
Dialog function
{
while (dialog not done)
{
Update
Draw screen behind dialog
Draw Dialog)
}
}
So basically, whenever a function invokes a dialog, the the Dialog function goes into an update/draw loop until the dialog is resolved, then returns to the calling function.
However, in Java, my main loop is not the infinite loop of {while (true){update;draw;}}, but rather the standard (AFAIK) Java method of a thread that looks like this:
public void update (Graphics g)
{
UpdateEverything();
Draw(g);
}
while (true)
{
repaint();
try
{
Thread.sleep (5);
}
catch (InterruptedException ex)
{
// do nothing
}
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
So there’s an outer thread that calls repaint and goes to sleep, at which point Java calls the update() function
But when I try to implement this same logic in my DoDialog function, it doesn’t work - I call repaint and go to sleep, but it never calls my update() function. This is probably because I’m already IN an update function (the main update function for the whole game loop). So is there a way to get it to do what I want? (i.e. allow a modal dialog, of my own control, with an infinite loop pending dialog resolution, INSIDE of the main update loop).
Hopefully this wasn’t completely incoherent. Alternate suggestions as to how to implement modal dialogs are also welcome.