java - Need to exit a loop and fix print order error (basic calculator) -


i'm trying make calculator activates upon request. i've had no problems activating calculator, i've struggled inputs etc. i've managed (kind of) working, need making exit loop, , print things in correct order. (more details below). here's code part:

public void calculate(){      for(int = 1; i<2; i++){          print("calculator activated" + "\n" + "please input first value" + "\n", false, new color(210, 190, 13));          try {             wait(keyevent.vk_enter);         }          catch (exception e1) {         }          input.addactionlistener(new actionlistener(){              public void actionperformed(actionevent e) {                  string text1 = input.gettext();                 double value1 = double.parsedouble(text1);                  print("please inout second value" + "\n", false, new color(210, 190, 13));                    try {                     wait(keyevent.vk_enter);                 }                  catch (exception e1) {                 }                  input.addactionlistener(new actionlistener(){                      public void actionperformed(actionevent e) {                  string text2 = input.gettext();                 double value2 = double.parsedouble(text2);                  double add = value1 + value2;                 double subtract = value1 - value2;                 double multiply = value1 * value2;                 double divide = value1 / value2;              print("add = " + add + "\n", false, new color(210, 190, 13));             print("subtract = " + subtract + "\n", false, new color(210, 190, 13));             print("multiply = " + multiply + "\n", false, new color(210, 190, 13));             print("divide = " + divide + "\n", false, new color(210, 190, 13));                 }         });     }         });     } } 

when runs, 'program' command prompt (whenever type , hit enter, prints out), , when input command "calculate", part of code begins. asks first value, , when put in, asks second value before printing out first value. i've tried:

sleep(1000); 

but seemed have no effect. [this happens when inputting second value; prints calculations before second value printed.]

furthermore, after prints calculations, (still before prints second value) says "please input second value" again. think issue leaving 'for' loop, really, have no idea.

i can't add images due being new user (need 10 rep)


Comments