Link to home
Start Free TrialLog in
Avatar of 3nigmatic
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 ?
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 3nigmatic
3nigmatic

ASKER

Sorry, im newish to Java ... what does the above mean ?
'ta' is your text area. You need to turn the text in it (which *can't* be int) into an int
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.
OK, I did as you said:

int temp = Integer.parseInt(armourPanel.headtxt.getText()); //armourPanel is a class + headtxt is my textArea
armourPanel.headtxt.setText(temp - armour); //armour is a method


I get the following error:

setText(java.lang.String) in javax.swing.text.JTextComponent cannont be applied to (int)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>armourPanel.headtxt.setText(temp - armour); //armour is a method

Setting is no different to getting

armourPanel.headtxt.setText(Integer.toString(temp - armour)); //armour is a method
CEHJ you are a legend.

Thanks very much.

Also thanks to sciuriware for the reasoning.
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 ?  >.<
:-)