Solved

How do i display numbers in a textfield

Posted on 2009-05-19
6
389 Views
Last Modified: 2013-12-14
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
Comment
Question by:chandanchoubey
  • 3
  • 3
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24427564
it won't be null when empty, it will instead contain an empty string.
check for that instead

0
 

Author Comment

by:chandanchoubey
ID: 24427596
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
 
LVL 92

Expert Comment

by:objects
ID: 24427601
don't think that will make a difference

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:chandanchoubey
ID: 24427615
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
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 24427629
you don't, you instead check for an empty string

txtPhone.getText().equals("")

0
 

Author Closing Comment

by:chandanchoubey
ID: 31583299
Excellent!! It worked thankyou very much!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now