I am working on a program with in interface that uses textAreas in order to recieve user input and at one point when I use the getText() function it tells me that the variable that I am trying to declare with it, an integer, must be a string. Would there be any other way to change this or would there be another function that I would use to call in integer from a textArea?
Edit:
Sorry, I did leave out some code for an example.
public void SetStock(javax.swing.JTextArea textStock)
{
Integer _textStock = textStock.getText();
}
public Integer getTextStock()
{
return _textStock;
}
This is the setter/getter that I am trying to use in order to use it within my main class.
You can use the text, and then parse it as an integer using
int i = Integer.parseInt(myText.getText());
also, Integer.parseInt
can throw an exception if the text is not a valid integer, so you might want to surround that in a try/catch block and catch the exception NumberFormatException
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With