Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

char to String  RSS feed

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
Hey!!
I wanted to ask a simple question. I am implementing a keylistener on a
textfield. As soon as a user types a character, it's clone is printed on
another textfield. For this I am using getKeyChar() method on the KeyEvent
object. It returns a char type on every key stroke. Now, how do I change this
char data type to a string type and show in the latter textfield. So the
actual thing to do is :
I type on TextField1 : abcdef
The System shows on TextField2 : abcdef
Finally, Swing's JPasswordField also has a method getPassword() to return a
char based (value or array). How do I convert it to a string and store in the
database or in TextField or in a physical file.
So Please help!!!
Bye,
Tualha Khan
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well you can convert the char arrray returned by getPassword like this

String s = new String(password.getPassword());
where password is JPasswordField...
this works because String class has constructor that takes char array as argument...
hope that helps

------------------
Sachin,
****************************************************
Learn from others mistakes. Life is too short to make all yourself.
****************************************************
 
Ranch Hand
Posts: 4702
9
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for your first question you can do this:
Character c = new Character(e.getKeyChar());
String s = c.toString();
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!