• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using java types

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
Matt Siegel
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic