Results 1 to 4 of 4
  1. #1
    Aash96 is offline Member
    Join Date
    Dec 2012
    Posts
    26
    Rep Power
    0

    Default Help with empty textfields!!!

    Hi, i have login screen where the user i asked to enter his username and password. Now if these fields are 'blank' i want to output and error message, but it does not seem to work. Nothing happens!!

    Here is my code: (NB. This is under my "Welcome" button...)

    if(username.equals(""))
    {
    JOptionPane.showMessageDialog(null,"The Username cannot be left blank!");
    }
    else if(password.equals(""))
    {
    JOptionPane.showMessageDialog(null,"The Password cannot be left blank!");
    }
    else if((username.equals(""))&&(password.equals("")))
    {
    JOptionPane.showMessageDialog(null,"Please fill in the required fields!");
    }

  2. #2
    EngineerVic is offline Member
    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0

    Default Re: Help with empty textfields!!!

    Have you tryed to compare your string with a null value instead of ""?

  3. #3
    Aash96 is offline Member
    Join Date
    Dec 2012
    Posts
    26
    Rep Power
    0

    Default Re: Help with empty textfields!!!

    i got it thanks :) Here is my new refurbished code :D :

    if((username.getText().equals("")&&(password.getTe xt().equals(""))))
    {
    JOptionPane.showMessageDialog(null,"Please fill in the required fields!");
    }
    else if(password.getText().equals(""))
    {
    JOptionPane.showMessageDialog(null,"The Password cannot be left blank!");
    }

    else if(username.getText().equals(""))
    {
    JOptionPane.showMessageDialog(null,"The Username cannot be left blank!");
    }

  4. #4
    EngineerVic is offline Member
    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0

    Default Re: Help with empty textfields!!!

    Good for you :)! I wrngly thought your username and password were of String type, not JTextField :)

Similar Threads

  1. TextFields not showing up
    By Army in forum New To Java
    Replies: 7
    Last Post: 06-20-2012, 06:36 PM
  2. textfields - cursor
    By newbie123 in forum AWT / Swing
    Replies: 6
    Last Post: 09-29-2011, 06:39 PM
  3. applet and textfields
    By poajavaweb in forum Java Applets
    Replies: 4
    Last Post: 01-28-2011, 08:56 PM
  4. adding textfields
    By themanepalli in forum Java Applets
    Replies: 1
    Last Post: 12-28-2010, 03:56 AM
  5. Buttons and TextFields
    By Xystus777 in forum New To Java
    Replies: 27
    Last Post: 03-17-2009, 01:26 AM

Posting Permissions

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