Solved

How do i display numbers in a textfield

Posted on 2009-05-19
6
395 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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 make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 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