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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "TEXTFIELDS TO INT" Watch "TEXTFIELDS TO INT" New topic
Author

TEXTFIELDS TO INT

Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Hi everyone
How do you make a textfield read as an int?
I know it has something to do with Integer.parseInt()
but do not know how it works.
I have six TextFields, named textField1, textField2, textField3 etc... and only 2 digits can be inserted.

TextField textField1 = new TextField(2);
TextField textField2 = new TextField(2);
etc...
but how do I make int an int???
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
int i = Integer.parseInt(texfield1.getText());


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Thank you thomas
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
if you were doing this for six textFields, int i would not work for all of them, so , what could be done to solve this.?

???
can something bedone to make this more simple?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Is there a reason that all the ints must be stored in the same variable? Perhaps creating a separate variable to hold each result might be a good idea?
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
well each text field id going to insert the users lottery numbers.The user can insert 6 numbers. and then once this is done when pressed ok this will let the computer generate its own random numbers.
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
i have added the Integer.parseInt within the textfields, it compiles successfully, but when I execute, the Applet does not initialise.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Do you get any exceptions when you run it? What does it do?


Dave
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
when I ran it with the textField changed to an int, it did not do anything, not even show my designed class.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Rupinder
Where in the code did you add the parseInt calls? Are in an event handler or in some other part of the code? Can you show the code where it is added - if it's a lot of code just show us a snippet and let us know where it falls in the whole thing.
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56

Hi Rupinder
I was just wondering, the way I understand this is the user must enter numbers into these TextFields and then click on the ok button, but why are you then adding action listener to each TextField ? if the code in actionperformed() should only be executed once the user presses the ok button this will never happen. because you have no action listener on the button , and from what I can see, it will execute for each key pressed in any of the Fields.
[ August 27, 2002: Message edited by: Thomas Paul ]

Any Body can be paid to write good code, but brilliant code can only come from passion
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
SO how do I attempt to make the button work with textFields1,2,3,4,5 and 6.
How do I make it like make the random generator work once button ok has been pressed.
I need it to generate and activate the textfields 7, 8, 9 ,10 ,11 and 12.>
So once ok is pressed it will automatically do this.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You want to add a listener to the button press and then process the text fields when the button is pressed. You don't need to listen for any events on the text fields.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TEXTFIELDS TO INT