-1

i am trying to do a presence check in java on 10 JTextFields. I want it so that if all 10 of my textfield have something in them, it will do my code.

String input1 = tfQ1.getText();
String input2 = tfQ2.getText();

etc.

I have put

IF(input1==("")&&input2==("")&&input3==("")&&input4==("")&&input5==("")&&input6==("")&&input7==("")&&input8==("")&&input9==("")&&input10==(""))
{
//DO SCORES ETC
}

However, this doesnt do anything... (my button does not work weather there are things in the text fields or not) Please and someone help with presence check validation? Thanks =)

2 Answers2

0

instead of "==" operator you should use

input1.equals("")
Orhan Obut
  • 8,756
  • 5
  • 32
  • 42
  • Thanks, this solves one problem but i have just realised, i dont know what i was it to equal to? The text fields are for a user to input a spelling for a spelling test and i want to check they have written an answer for every question? Do you know how to make it so it checks for any input, not a specific word =) Thanks, sorry im being a pain, im new to this –  Feb 19 '14 at 19:31
0
if(input.equals("WhateverYouAreLookingFor")) {
    //do this
}else {
    //do this
}

== is a reference comparison, both objects point to the same location in memory. essentially it tests wether the two operands refer to the same object.

.equals() will only compare what is in the String. It can be overridden so two distinct objects can still be equal.

  • Thanks, this solves one problem but i have just realised, i dont know what i was it to equal to? The text fields are for a user to input a spelling for a spelling test and i want to check they have written an answer for every question? Do you know how to make it so it checks for any input, not a specific word =) Thanks, sorry im being a pain, im new to this –  Feb 19 '14 at 19:30