Results 1 to 2 of 2

Thread: method / if statement

  1. #1

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407

    method / if statement

    can someone explain to me why this isnt working? It is supposed to show the next form if the username is correct and it doesnt work. What am I doing wrong here?

    Code:
     private void btnLoginMouseClicked(java.awt.event.MouseEvent evt) {                                      
    
            if(txtUsername.getText() == "jeff"){
                //If login is successful, load main frame
                MainFrame newMainFrame = new MainFrame();
    
                newMainFrame.setVisible(true);
    
                this.dispose();
            }        
           
     }
    I did a System.out.println(txtUsername.getText()); before the if statement and it did show up. I don't understand why the code in the if statement is not being executed. Thanks.

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: method / if statement

    txtUsername.getText()
    Put a system.out.println statement outside the if statement with that line of code. also make sure you trim the text to get rid of white space. another thing, you should use .equals() in string comparison rather than ==.

    Code:
    if ( txtUsername.getText().trim().equals("Jeff") )
    {
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width