Hi all ;-) Situation: I'm writing an math application,and I need some fields in my GUI to enter the calculation params(lenght for example). The TextField with getText method (you have explained me grately) returns a String;I need the method read a double or int from the field to use in aplication's further calculations. How shall I do this? And what about sending the result back to my window? (setText or drawText use Strings too) Thank's very much.
Matt Senecal
Ranch Hand
Joined: Dec 01, 2000
Posts: 255
posted
0
To make a double from a String:
To make an int:
There's nothing more dangerous than a resourceful idiot. ---Dilbert
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
posted
0
Dominik To get an int or double from a string you'd use one of the wrapper classes. Check out the Integer and Double classes in the java.lang.Number package. Both of these classes have methods that will take a String value and return a primitive. For example to get a double from a String you would do somehting like this:
After that code the variable dbl will have the primitive double value of 2.456 Hope that helps
------------------ Dave Sun Certified Programmer for the Java� 2 Platform
Dave
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.