Q:

How to maintain an infinite loop with multiple buttons?

Alright so basically what I am trying to do is load my GUI with three buttons, "Clear", "Calculate", and "Quit". Through an infinite for loop, when I press Calculate I want it to break the loop. I have the code for the button functionality but when I press Quit before I press Calculate I get a NullPointerException (The button still closes the GUI but I get an error). What do I have to do in order to get rid of this error?
Here's my code:
form = new BasicForm("Clear", "Calculate", "Quit");
buildForm();

for ( ; ; ) {
  button = form.accept();

  switch(button) {

    case 0:
      form.clearAll();
      break;

    case 1:
      // calculate code goes here
      break;

    case 2:
      form.close();
      break;
  }
}

A:

I think this will resolve your NPE error:
form = new BasicForm("Clear", "Calculate", "Quit");
buildForm();
boolean quitCalled=false;

for ( ; ; ) {
button = form.accept();

switch(button) {

case 0:
  form.clearAll();
  break;

case 1:
  // calculate code goes here
  break;

case 2:
  form.close();
  quitCalled = true;
  break;
}
if(quitCalled)
{
break;
}
}

