I have an int value that I have incremented by one. Now I need to add this value to a JTextField. Here is my code so far: int newvend = 17000; newvend++; // This is the part I need help on. ivjvendno.setText(newvend); Do I need to change the value to a String? If so, what is the syntax for this? Do I have the right syntax to put the value of 'newvend' into my JTextField? (ivjvendno is the JTextField). Any help is appreciated. Thanks so much!
You need to use the Integer wrapper class. You could do it a couple of ways with the Integer class, but this is probably the best way: int newvend = 17000; newvend++; ivjvendno.setText(Integer.toString(newvend)); // Static toString method in Integer You could also create a new instance of the Integer class and use toString() on that. Each primitive type (int, float, etc.) has a wrapper class (Integer, Float, etc.) that are extremely useful. They are all in the java.lang package: http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html HTH! Matt
Joined: Feb 28, 2001
Thanks a bunch Matt! This really does help me. I'm just starting out with java and am having a hard time putting everything together. For some reason, I still keep wanting use RPG logic on everything. Guess, I'd better get out of that mode, huh! Thanks again!