1

Ok, so i have a Text Box. This Text Box has the word BLAHH written in it. The part I don't get is how I change the text in the TextBox to an Int? I have tried putting the Int into string form. I am not trying to put the string back into Int form. im trying to have the string change the text where it displays the int number...

    //---- Money ----
    String str = Integer.toString(money); 
    Money.setText(str);
    add(Money, CC.xy(21, 1));

P.s. I'm using the JFormDesigner Plugin for Eclipse!

thejartender
  • 9,339
  • 6
  • 34
  • 51
Yloplopy
  • 13
  • 5

1 Answers1

3

If you have a string "str" you can convert it to an int using this:

String str = Money.getText();
try {
int number = Integer.parseInt(str);
}
catch (NumberFormatException e) {
//What to do if Money did not hold an int?
}
Florian
  • 81
  • 2
  • I'm not trying to convert it back to a int. I'm trying to change the text to that string that holds the int "money" – Yloplopy May 21 '12 at 00:49
  • I've tried what you put up there, and also tried to change it to a word. Nothing happens. The only way to accually change the text is to set it. I have tried to set it to an int as well as a string. Nothing is working... – Yloplopy May 21 '12 at 01:25
  • You can´t do integer operations with strings. If i get you right on what you want to do, you will have to convert the string to an int, do the integer operations and cast it back again to put it into the textbox. – Florian May 21 '12 at 14:16