In java, I am currently in the process of trying to find a way to do mathematical sums by typing in text to a JTextField, putting it into a String, and converting it to an int and solving. The problem is however, I don't want to simply put a *number* into the string but an actual *sum* including addition, subtraction etc.

Currently it will accept just doing something like, 1 which will go from string and convert to an int, but when I do '1+1' or even just '1+' it throws exceptions everywhere because '+' isn't a number.  

Which I already understand that it wont work because int's only allow numbers.

Is there a way I can safely type a complete sum into the text field and convert it to an int somehow? Like typing 7-2\*5 and then the answer being held in an int?

Thanks.