Results 1 to 12 of 12
  1. #1
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default Equivalent of PHP isset in JAVA

    I have a GUI that takes a string in a text field. There some conversions (parse string to double) that happen the moment someone clicks the button. If nothing is in there exception exception, something I want to stop.

    So I want something to check if the variable that receives this String has anything in it. Does stringVarible != null suffice?

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    It's a very difficult to understand that you want.
    Do you want to check some parameters on not null, when you click on a button?

    I don't advise you compare to Java and PHP. There are very difference language.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    I want to make sure that something has been entered in a TextField when the button is pressed.

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    It's easy. You can make yourself listener for JButton. It would take a refer on JTextField object. In class a listener you will check a value from JTextField and if it's not null you will do something.
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    Thanks, some rep for you

  6. #6
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    it's good. if it's clear. I think you can show some short example. It will be a very useful for newbie, if they will have same question.
    Skype: petrarsentev
    http://TrackStudio.com

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,765
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Petr View Post
    It's easy. You can make yourself listener for JButton. It would take a refer on JTextField object. In class a listener you will check a value from JTextField and if it's not null you will do something.
    The text String in a JTextField is never equal to null; at least it is the empty String "".

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by africanhacker View Post
    If nothing is in there exception exception, something I want to stop.
    It might have been an idea to actually tell us what the exception was...

  9. #9
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    JosAH you are quite right. I have just realised that !=null will not work. "" is the way to go with something like equalsIgnoreCase or something along those lines. At least that is what worked for me

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,765
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by africanhacker View Post
    JosAH you are quite right. I have just realised that !=null will not work. "" is the way to go with something like equalsIgnoreCase or something along those lines. At least that is what worked for me
    Or just do this:

    Java Code:
    if (field.getText().length() == 0)
       // no text in the field ...
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    I'm still curious what the actual excpetion was...but maybe that's just me.

  12. #12
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

Similar Threads

  1. Java equivalent of PHP's variable-variables?
    By XmisterIS in forum New To Java
    Replies: 7
    Last Post: 09-01-2010, 12:05 PM
  2. Java equivalent of Linux 'find' function
    By porchrat in forum New To Java
    Replies: 5
    Last Post: 08-25-2010, 12:31 PM
  3. [SOLVED] Java equivalent to X11 Work Procedure
    By LongHitter in forum New To Java
    Replies: 0
    Last Post: 01-12-2009, 12:36 PM
  4. Filter a file in java (unix cut command equivalent)
    By marcosabel in forum New To Java
    Replies: 0
    Last Post: 02-11-2008, 08:26 PM
  5. Php explode function, equivalent java
    By fernando in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 06:44 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
  •