Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9049299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:21:47+00:00 2026-06-16T12:21:47+00:00

I am writing a login script for a game that i have made. I

  • 0

I am writing a login script for a game that i have made. I am currently in the process of checking the information given to make sure it is valid. I have run into the problem that when I go to check to see if 2 text fields have the same value. When they do they do the opposite of what i want it to do.

private void regAccConfEmailFieldFocusFocusLost(FocusEvent event) {
    if(regAccConfEmailField.getText() == regAccEmail.getText() && regAccConfEmail != null)
    {
        regAccConfEmailField.setBorder(new LineBorder(Color.green, 1, false));
        confEmail = true;
    }
    else
    {
        regAccConfEmailField.setBorder(new LineBorder(Color.red, 1, false));
        confEmail = false;
    }
}

private void regAccConfSecQFieldFocusFocusLost(FocusEvent event) {
    if(regAccConfSecQField.getText() == null)
    {
        regAccConfSecQField.setBorder(new LineBorder(Color.red, 1, false));
        secQuestion = false;
    }
    else
    {
        regAccConfSecQField.setBorder(new LineBorder(Color.green, 1, false));
        secQuestion = true;
    }
}  

This is the code that i have, and i need to know why each of these methods does the opposite of what it is given.

Say that regAccConfEmailField and regAccEmailField both equal hello@gmail.com
It will go to the if statement and not the else. If needed, i can provide more code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T12:21:48+00:00Added an answer on June 16, 2026 at 12:21 pm

    There are 2 issues with this statement:

    if (regAccConfEmailField.getText() == regAccEmail.getText() && regAccConfEmail != null)
    
    • You should have the null check first so that it short-circuits the expression if regAccConfEmail is null
    • Also use String.equals to compare String content instead of the == operator. The == operator is used to compare object references and is currently giving you the opposite of what you want as the values from the 2 fields will be different String objects.

    You can replace with

    if (regAccConfEmail != null && regAccConfEmailField.getText().equals(regAccEmail.getText()))
    
    • Also regAccConfSecQField.getText() can never be null from a JTextField so replace

      if (regAccConfSecQField.getText() == null)

    with

      if (regAccConfSecQField.getText().trim().isEmpty())
    
    • Finally, you appear to be using a FocusListener which relys on FocusEvents for performing the validation. Have a look at using an DocumentListener for triggering validation on document changes.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a perl script that should login to Gowalla, fetch some information
I'm currently writing a PHP login script and trying to make it as secure
i am writing web-services for login script. Which i have to keep on HTTPS
I am currently re-writing my functions script (PHP) for my login system. Is the
I am currently writing a site that will require a login to use. I
I'm writing some script, that works with web-servers. So, I have the following code:
I'm currently writing a script that grabs a file from a website and then
I have an ssh script that uses a local key for login to the
I'm new to JavaFX and I'm writing a simple login application that I would
I'm writing an application that displays Google Map right after the login screen. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.