aspose file tools*
The moose likes Beginning Java and the fly likes Using java types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using java types" Watch "Using java types" New topic
Author

Using java types

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
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

Joined: Jul 18, 2000
Posts: 55
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

Joined: Feb 28, 2001
Posts: 455
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using java types