I feel like “if((text.equals(degree90))||(text.equals(degree89))” can be improved since I want to do from degree0 to degree90. Any help would be greatly appreciated.
Welcome to the forum!
Is there any specific sequence of numbers?
You could try regex to get the numbers or depending on the input you could try to convert the string into an integer to get the number and check if it is either inside an interval or present in an array of expected values. Examples on how to convert the string into integer are below:
String a = "90";
int b = Integer.parseInt(a);
println("B=" + b);
String c = "degree90";
int d = Integer.parseInt(c.replaceAll("[\\D]", ""));
println("D=" + d);
Looks good! One suggestion – update degree=int(0+text); in keyPressed just after you update text=text+key. Otherwise it is possible that a new key+enter might both get processed by keypressed before degrees gets updated on the next frame, and then enter will be ignored even though the text value is correct.