File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TEXTFIELDS TO INT

 
Rupinder Bains
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int i = Integer.parseInt(texfield1.getText());
 
Rupinder Bains
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you thomas
 
Rupinder Bains
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you get any exceptions when you run it? What does it do?
 
Rupinder Bains
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
hennie louw
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Rupinder Bains
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic