?
Solved

How do i display numbers in a textfield

Posted on 2009-05-19
6
Medium Priority
?
398 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 

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 1000 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

Industry Leaders: 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!

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month9 days, 2 hours left to enroll

764 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