Originally Posted by
steme
Here is a line of code from one my EXAMPLE scripts I am trying to reproduce. BUT in my assignment I want my text box to be receiving a INT not a String. So instead of "jtf.Message.getText();" I would like to imagine I could just type in getINT or something simple but that is obviously not the case. How can I get a int?
Easiest way that you can do in 1 chained line or a few lines is to first keep jtf.Message.getText() as that retrieves and represents the value as a String object. To get that into a primitive int, you should first use the int's wrapper class (Integer), which "converts" it from a String object to an Integer object. Next, the .parseInt() method basically parses the Integer object as a primitive int. The one problem with this is this conversion is vulnerable to the user entering inappropriate data, such as letters, symbols, nothing at all, decimals or really big integers. These can be addressed though by try-catch blocks or throwing exceptions.