3nigmatic
asked on
Variable type issue
Hey folks,
I have a comboBox which is populated by an array of strings.
I then have a textArea which is automatically filled with a number from another array depending on what value is selected from the comboBox.
I also have a simple maths method that produces a random number.
Where the problem lies is when I try to do any arithmetic operations to the text in the textArea, I receive an error about incompatible variable types: found String, requires int.
Yet the value in the textArea IS an int.
Any ideas please ?
I have a comboBox which is populated by an array of strings.
I then have a textArea which is automatically filled with a number from another array depending on what value is selected from the comboBox.
I also have a simple maths method that produces a random number.
Where the problem lies is when I try to do any arithmetic operations to the text in the textArea, I receive an error about incompatible variable types: found String, requires int.
Yet the value in the textArea IS an int.
Any ideas please ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'ta' is your text area. You need to turn the text in it (which *can't* be int) into an int
ASKER
Ahhh, ok I see.
Out of curiosity, why are you not allowed int values in a textArea ? Are they allowed in TextFields ?
Thanks for the help.
Out of curiosity, why are you not allowed int values in a textArea ? Are they allowed in TextFields ?
Thanks for the help.
ASKER
OK, I did as you said:
int temp = Integer.parseInt(armourPan el.headtxt .getText() ); //armourPanel is a class + headtxt is my textArea
armourPanel.headtxt.setTex t(temp - armour); //armour is a method
I get the following error:
setText(java.lang.String) in javax.swing.text.JTextComp onent cannont be applied to (int)
int temp = Integer.parseInt(armourPan
armourPanel.headtxt.setTex
I get the following error:
setText(java.lang.String) in javax.swing.text.JTextComp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>armourPanel.headtxt.setT ext(temp - armour); //armour is a method
Setting is no different to getting
armourPanel.headtxt.setTex t(Integer. toString(t emp - armour)); //armour is a method
Setting is no different to getting
armourPanel.headtxt.setTex
ASKER
CEHJ you are a legend.
Thanks very much.
Also thanks to sciuriware for the reasoning.
Thanks very much.
Also thanks to sciuriware for the reasoning.
ASKER
woops, did the answer thing the wrong way round .... sorry about that.
Hoping CEHJ got the 450 though .... if not can an admin sort this please ? >.<
Hoping CEHJ got the 450 though .... if not can an admin sort this please ? >.<
:-)
ASKER