Solved

How do i display numbers in a textfield

Posted on 2009-05-19
6
392 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

948 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