• Post Reply Bookmark Topic Watch Topic
  • New Topic

A Warning !??

 
vikas de
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
JPasswordField userPassword=new JPasswordField(10);
userPassword="pw";
String test=userPassword.getText().trim();
i am using the above statements and while compiling it displays the following warning.
Note: pro.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
and if i recompile with -deprecation it displays the following warning.
pro.java:597: warning: getText() in javax.swing.JPasswordField has been deprecated

String test=userPassword.getText().trim();
^
please tell me how to remove this warning !!!
Thanx
vikas
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
??? How can this possibly compile at all? On the second line, you're attempting to assign a String to a JPasswordField. Surely the compiler will report that error before informing you of deprecated methods. As for the latter, it's a simple matter to consult the API for inormation about the deprecated method, and a suggestion about what to replace it with. Always consult the API.
 
Michael Hildner
Ranch Hand
Posts: 297
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use:
String myString = new String(passwordField.getPassword());
since that return an array of chars.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!