Re: Parsing or Casting a JtextField? Help requested....
- From: Eric Smith <eric@xxxxxxxxxxxx>
- Date: 27 Feb 2007 23:45:01 -0800
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().
.
- Follow-Ups:
- Re: Parsing or Casting a JtextField? Help requested....
- From: Tamer Higazi
- Re: Parsing or Casting a JtextField? Help requested....
- References:
- Parsing or Casting a JtextField? Help requested....
- From: Tamer Higazi
- Parsing or Casting a JtextField? Help requested....
- Prev by Date: Re: Parsing or Casting a JtextField? Help requested....
- Next by Date: Re: Handling exceptions in SwingWorker
- Previous by thread: Re: Parsing or Casting a JtextField? Help requested....
- Next by thread: Re: Parsing or Casting a JtextField? Help requested....
- Index(es):
Relevant Pages
|