chandanchoubey
asked on
How do i display numbers in a textfield
I have made three textfields (txtPhone, txtMobile & txtCount) and one button (btnAdd). I want third (txtCount) field to display 1 when there is something in either txtPhone or in txtMobile. & if both the fields have something I want txtCount to display 2. its displaying 2 no matter any field has anything or not. what am I doing wrong?
Please check my code. Thanks.
Please check my code. Thanks.
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// Window activated handling code here:
txtPhone.setText(null);
txtMobile.setText(null);
}
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
if((txtPhone.getText() != null) && (txtMobile.getText() !=null))
{
txtCount.setText("2");
}
else if((txtPhone.getText() != null) || (txtMobile.getText() !=null))
{
txtcount.setText("1");
}
else
{
txtcount.setText("0");
}
}
ASKER
Thanks for your quick response. But I also guessed that for that I have put this code to make sure it is null when window fires up.
private void formWindowActivated(java.a wt.event.W indowEvent evt) {
// Window activated handling code here:
txtPhone.setText(null);
txtMobile.setText(null);
}
private void formWindowActivated(java.a
// Window activated handling code here:
txtPhone.setText(null);
txtMobile.setText(null);
}
don't think that will make a difference
ASKER
Thanks again. Please suggest me then how do I do this. How do I make sure that the text fields are null when program starts.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent!! It worked thankyou very much!!
check for that instead