Results 1 to 6 of 6
  1. #1
    zhider is offline Member
    Join Date
    Oct 2012
    Posts
    37
    Rep Power
    0

    Default Swing boolean/String problem

    in this code, I am having trouble with booleans and strings. I set name variable as a String and newname as a boolean. The problem with this is that I need to print newname and cannot print a boolean. When I change it to a string it says it found boolean and gives me an error. Any ideas?

    private void CheckNameButtonActionPerformed(java.awt.event.Acti onEvent evt) {
    String name;
    name= OriginalNameInput.getText();
    Boolean newname = convertName(name);
    OutputLabel2.setText(newname);
    }
    public static boolean hasComma(String name){
    boolean oName;
    int x= name.indexOf(',');
    if (x == -1) {
    oName= false;
    }else{
    oName= (true);
    }
    return (oName);
    }
    public static boolean convertName(String name) {
    boolean convert = false;
    hasComma(name);
    if (hasComma(name)== true) {
    System.out.println (name);
    }else{
    String s = name;
    String[] arr = s.split(" ");
    System.out.println (arr[1]+ ", "+ arr[0]);
    }
    return (convert);
    }

  2. #2
    zhider is offline Member
    Join Date
    Oct 2012
    Posts
    37
    Rep Power
    0

    Default Re: Swing boolean/String problem

    Anyone??

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Swing boolean/String problem

    Quote Originally Posted by zhider View Post
    The problem with this is that I need to print newname and cannot print a boolean.
    A print method that takes a boolean value exists. But looking at your code it seems you want to set the text of a label which indeed needs a String. So why not convert the boolean value to a String. Check out the String class or Boolean class. Both have a method to do this.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Swing boolean/String problem

    Guide For New Members
    BB Code List - Java Programming Forum
    Code Conventions for the Java Programming Language: Contents

    Also, bumping a thread after waiting just 19 minutes is extremely rude.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    zhider is offline Member
    Join Date
    Oct 2012
    Posts
    37
    Rep Power
    0

    Default Re: Swing boolean/String problem

    So is replying with no helpful comments

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Swing boolean/String problem

    Quote Originally Posted by zhider View Post
    So is replying with no helpful comments
    Actually they are quite helpful. If you can show us code with code tags, then we can actually read the code and understand it and be better able to help you. If you take his recommendations to heart, I guarantee you'll have a better experience here (and so will we!).

Similar Threads

  1. Input String to boolean equation
    By rru96 in forum New To Java
    Replies: 10
    Last Post: 09-23-2012, 11:21 AM
  2. convert boolean to string
    By newbiejava in forum New To Java
    Replies: 3
    Last Post: 07-22-2010, 04:32 PM
  3. Replies: 0
    Last Post: 03-16-2010, 12:08 PM
  4. Limiting loop in boolean string
    By jimmy-lin in forum New To Java
    Replies: 7
    Last Post: 10-10-2009, 07:31 AM
  5. boolean to string
    By otoro_java in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 06:31 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
  •