Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in getting string from jTextField  RSS feed

 
Amarjeet Anand
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...

i have a jTextField named pIdTextField on a JFrame along with a button named btnSave . i want that when pIdTextField is blank... then it should show a message Saving. i have tried in the code below...



but when ever i click the btnSave button .... it always displays the message as Updating. . it never show the message as Saving.. i have tried "" instead null in the if condition .. but it doesn't show "Saving."
please help me... waiting for your kind response.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The empty String "" and null aren't the same thing.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amarjeet Anand wrote:i have tried "" instead null in the if condition

Did you use == or the equals method to compare with "" ?
 
Amarjeet Anand
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart A. Burkett

sir
i have tried == as---



but this too dos'nt solve my probleum that when the pIdTextField is left blank.... message Saving. should display.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amarjeet Anand wrote:i have tried ==


Yeah, well don't do that. If you want to compare to see if two String objects contain the same data (even if that's no data) then use the equals() method to do the comparison.
 
Amarjeet Anand
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot Paul Clapham
as you suggested... i have tried the code below and it worked perfectly...



thanks a lot again sir... :-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!