Re: Parsing or Casting a JtextField? Help requested....



From the runtime the values in a JTextField have to be assigned to a
variable with the following datatype:

short
byte
int

I don't know how to do that!

For any help

Thank you

Tamer

Eric Smith schrieb:
Tamer Higazi <no@xxxxxxx> writes:
I have a JTextField which receives at runtime a value. Now this value
has to be inserted with a specialtype (not text) in a database.

In the java chat somebody told me that I have to parse. I know only on
C++ that the conversion a value from one datatype to one other has to be
casted.

What kind of value? A numeric value? A string? Parsed how?

You get the String value from the JTextField by using the getText() method.

If you want to treat it as an integer, you can pass that String to
Integer.parseInt() or Integer.valueOf(). Those will throw a
NumberFormatException if the String can't be parsed as an integer.
There are similar methods Long.parseLong(), Long.valueOf(),
Short.parseShort(), Short.valueOf(), Float.valueOf(), and
Double.valueOf().
.


Quantcast