Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: what's wrong with this function?

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default what's wrong with this function?

    I've defined this function in a .js file. It's supposed to take a color, make it the background color in a table cell, and adjust the color of the text depending on whether the color is dark or light. What is wrong with the code?

    function brighttest(season)
    {

    String fontColor = season;

    // remove hash character from string
    String rawFontColor = fontColor.substring(1,fontColor.length());

    // convert hex string to int
    int rgb = Integer.parseInt(rawFontColor, 16);

    Color c = new Color(rgb);

    float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);

    float brightness = hsb[2];

    if (brightness < 0.5) {
    document.write('<td width="25%" bgcolor="'+season+'">');
    document.write ('<font color="#FFF8C6">'+season+'</font>'); //prints the value
    } else {
    document.write('<td width="25%" bgcolor="'+season+'">');
    document.write ('<font color="#000000">'+season+'</font>'); //prints the value
    }
    }


  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    20
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default Re: what's wrong with this function?

    Quote Originally Posted by victorsaur View Post
    I've defined this function in a .js file. It's supposed to take a color, make it the background color in a table cell, and adjust the color of the text depending on whether the color is dark or light. What is wrong with the code?
    What is the error?

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: what's wrong with this function?

    Moved to Other Programming Languages
    javascript != java. Your code is javascript, and this is a java forum. You might try your luck on a javascript dedicated forum

  4. #4
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: what's wrong with this function?

    It causes all other links to images and text to not show up... and I'm sure that it is not calling the function itself, rather the function that has some error.

Similar Threads

  1. Function in Function?
    By junxiqqq in forum Java Theory & Questions
    Replies: 5
    Last Post: May 18th, 2012, 08:05 PM
  2. need help with a function...
    By fallout87 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 2nd, 2011, 05:42 AM
  3. About the ackermann function...
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 25th, 2011, 09:24 AM
  4. Need Help on the Interface Function
    By yel_hiei in forum Object Oriented Programming
    Replies: 12
    Last Post: July 29th, 2010, 07:27 AM
  5. Function of difference between two numbers
    By uplink600 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 13th, 2009, 05:57 AM