stop while statment with messagebox java – Education Career Blog

I need to find a way to stop a while statement when a messagebox is closed in java. I am modifying a chat program, the server has no gui and listens with a while(true) statement. I am trying to find a way to close the server with out going into task manager and killing java.exe. I have little experience with java so some source code would be nice. Thanks for the help!

EDIT:
I decided to got wiht a different chat program. Thanks for the help!

,

Perhaps I’m misunderstanding, but shouldn’t the status of the messagebox be part of the while condition? If you can’t access the messagebox directly in the loop, you could break this out into a method which returns a boolean value based on the status of the message box.

,

You can use a “break;” to exit any loop in Java:

while (isRunning)
{
    // Code

    if (somethingHappened)
    {
        break; // break out of loop
    }
}

Leave a Comment