Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to find user put nothig in JTextField?  RSS feed

 
mira yang
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the user give a nickname when login,but how to find he put nothing?
Thanks!
 
Sebastiaan Kortleven
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if (textfield.getText().equals("")) System.out.println("Nothing entered");
 
Java Programmer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do following:
1. String temp=new String("");
2. if((temp.compareTo(textField.getText())==0)
 
Java Programmer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do following:
I think This will work :
//---Your Code
String temp=new String("");
if((temp.compareTo(textField.getText())==0){
JOptionPane.showMessageDialog(null,"Enter Nick Name",JOptionPane.ERROR_MESSAGE);
/* plaease check the API for JOptionPane.showMessageDialog() */
//--Your Code
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java Programmer,
We have a Naming Policy that all our members must adhere to. Please read this and adjust your display name accordingly.
You can change your display name here.
It appears that you have been warned about your display name 3 times already. I would like to inform you that not adhering to our Naming Policy can result in your account being locked and possibly your IP being blocked from our site. Please adjust your display name to avoid these actions. Come on...conform...be one of us.
 
Carlos Failde
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A similar topic mentions the user of an InputVerifier.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note, also, that most "Java Programmer"s would write the following code:

more efficient, as well as far more readable
 
Robert Tiffer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use

just in case the user had entered whitespace. Too anal? Can't help it, I'm addicted to the trim() method.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

just in case the user had entered whitespace. [/qb]<hr></blockquote>
You cannot be sure, whether a whitespace might be a valid input, since we don't know to much of the context it's used.
But of course

is better readable.
[ April 21, 2004: Message edited by: Stefan Wagner ]
 
Jason Steele
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another example:
if(textBox.getText().trim().length() == 0) { // do stuff }
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!