Results 1 to 3 of 3
  1. #1
    überfuzz is offline Member
    Join Date
    Feb 2011
    Posts
    43
    Rep Power
    0

    Default Trying to use the type color

    I'm trying to get use a method that takes an argument of the typ Color. The method is used to set/change color of an object.
    Method
    Java Code:
      public void setColor(Color color) { this.setBodyColor(color); }


    Trying to use it
    Java Code:
    test.setColor(red);


    How do I set the color to red if I have these colors?
    Java Code:
    private static Color[] colorArray = { Color.green, Color.cyan, new Color(255,0,255), Color.gray, Color.red, Color.black};

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by überfuzz View Post
    How do I set the color to red if I have these colors?
    Java Code:
    private static Color[] colorArray = { Color.green, Color.cyan, new Color(255,0,255), Color.gray, Color.red, Color.black};

    you can use the position of the red color inside your colorArray to get the red element and then

    test.setColor(colorArray[4);

    watch out: the index of an array is zero-based!

  3. #3
    überfuzz is offline Member
    Join Date
    Feb 2011
    Posts
    43
    Rep Power
    0

    Default

    Yes, but color is private. I thought the gnarly was that I had to get the colorarray before I could use it..? Your example doesn't work. Hmm...

    Edit, I got it, thanks.
    Last edited by überfuzz; 02-07-2011 at 12:36 PM. Reason: Solved

Similar Threads

  1. Change text color on type
    By corbokhan in forum New To Java
    Replies: 2
    Last Post: 11-01-2010, 08:30 PM
  2. [COLOR="Navy"]execute .bat file in mysql [/COLOR]
    By msankar.ravi in forum Networking
    Replies: 0
    Last Post: 02-24-2010, 05:27 AM
  3. Question about Strings and Color type
    By Psyclone in forum AWT / Swing
    Replies: 1
    Last Post: 02-16-2010, 06:28 PM
  4. using instanceof to get Object type and parent type?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-06-2008, 07:24 PM
  5. [SOLVED] Cast string type to int type
    By GilaMonster in forum New To Java
    Replies: 9
    Last Post: 09-17-2008, 11:43 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
  •