• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

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.
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");
       }
}

Open in new window

0
chandanchoubey
Asked:
chandanchoubey
  • 3
  • 3
1 Solution
 
objectsCommented:
it won't be null when empty, it will instead contain an empty string.
check for that instead

0
 
chandanchoubeyAuthor Commented:
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.awt.event.WindowEvent evt) {
        // Window activated handling code here:
       
        txtPhone.setText(null);
        txtMobile.setText(null);
    }
0
 
objectsCommented:
don't think that will make a difference

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
chandanchoubeyAuthor Commented:
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.
0
 
objectsCommented:
you don't, you instead check for an empty string

txtPhone.getText().equals("")

0
 
chandanchoubeyAuthor Commented:
Excellent!! It worked thankyou very much!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now