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
Solved

How do i display numbers in a textfield

Posted on 2009-05-19
6
393 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java jdbc batch example 8 41
jsp login check 12 42
printf performancy 11 69
java imports not found 4 26
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

856 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