I am trying to make a gui calculator using Java swing, but there is something i have no idea how to do that. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I am trying to make a gui calculator using Java swing, but there is something i have no idea how to do that.

As already mentioned that I'm trying to make a gui calculator, So the problem is that how to stop or restrict the user to use any operator key more then once simultaneously. Let's suppose if the user had already entered 45+ then the user hits any operator key again then it will be like 45++ or 45+- etc, which is clearly an invalid expression. Any help or ideas will be appreciated 😊😊

20th Mar 2020, 12:06 AM
Amarjeet Kumar
Amarjeet Kumar - avatar
1 Answer
+ 2
There are many ways to do this. You could simply do something like this: boolean operator = false; if(key == '-' && !operator){ operator = true; //Your subtraction code here } if(key is a number){ operator = false; }
20th Mar 2020, 1:40 AM
Jax
Jax - avatar