Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to compare values in text box

 
Shamsa Aziz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Salaam!

How do I compare passwords from two text boxes and can generate a popup dialog if both doesn't match?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I presume you know how to get text from text boxes with their methods? And how to compare the text, which is a String? You will probably find a dialogue the simplest form of popup; try option panes. Note that API link contains a Java Tutorials link, which will probably help, too.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way: there is a special text component designed for passwords. I can’t remember its name, but it is something like JPasswordField.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a Java or JavaScript question?
 
Shamsa Aziz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you campbell

here's how I did

if(!(Password.getPassword().equals(Password2.getPassword())))
{
JOptionPane.showMessageDialog(null, "Not matched");
}
But not working for me
 
Shamsa Aziz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Is this a Java or JavaScript question?


It's java, I have created a login form in Jfram and want to do a comparison of password and retype password fields. The form should only be submitted if both the fields match
 
Vinod Tiwari
Ranch Hand
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check Java docs



You have to pass parentComponent value which in your code is null.
 
Shamsa Aziz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinod Tiwari wrote:Please check Java docs



You have to pass parentComponent value which in your code is null.



Is that really the problem? I mean solution?
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shamsa Aziz wrote:
Darryl Burke wrote:Is this a Java or JavaScript question?


It's java, I have created a login form in Jfram and want to do a comparison of password and retype password fields. The form should only be submitted if both the fields match


The reason I asked is because Java doesn't have anything called a "text box" -- which you mentioned in your first post.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shamsa Aziz wrote:
Vinod Tiwari wrote:Please check Java docs



You have to pass parentComponent value which in your code is null.



Is that really the problem? I mean solution?


No, it's not important at all. Shamsa, there is absolutely no problem with passing null as the parentComponent argument to a JOptionPane method.

For your solution, check out the equals(...) methods of java.util.Arrays
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another catch is that when you pass null as the first argument to that JOptionPane method, the dialogue window appears in the centre of the screen, but might be behind other windows on your screen.
 
Shamsa Aziz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!

My code is running successfully now so I want to share what I did.

I have converted the password into Strings and then did a comparison.
I did like this

String password= new String(Password.getPassword());
String password2= new String(Password2.getPassword());
If(!(password.equals(password2))
{
.......
}

and it works

Thank you All.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well done
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic