Colors in Java

  • Comp Sci
  • Thread starter Nick M
  • Start date
  • #1
Nick M
192
0
I'm trying to set the color using three integer values for R, G, and B stored in three int type variables (these values are randomly generated between 0 and 255).

Previously we set the color (e.g. yellow) using g.setColor(Color.YELLOW).

I'm unsure of how to do this. The course is online, and I've read the text section multiple times.
 

Answers and Replies

  • #2
chroot
Staff Emeritus
Science Advisor
Gold Member
10,275
40
Look at the API documentation for whatever class is the object g belongs to. There will be a number of overloaded methods, call called setColor, but which accept different arguments. One of them may accept a Color object, and that should prompt you to look at the documentation of the Color class. You will find that you can construct a Color object with three arguments, red, green, and blue.

- Warren
 
  • #3
Nick M
192
0
Hmmm... I've looked around the API and can't seem to find the code needed to set the color using RGB values.

Knew I shouldn't have taken an online class... :mad:
 
  • #4
rootX
465
4
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Color.html [Broken]

You are looking for this constructor:
Color(float r, float g, float b)
 
Last edited by a moderator:

Suggested for: Colors in Java

  • Last Post
Replies
7
Views
756
Replies
17
Views
666
  • Last Post
Replies
7
Views
800
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
12
Views
756
  • Last Post
Replies
1
Views
505
  • Last Post
Replies
1
Views
567
Replies
2
Views
619
  • Last Post
Replies
2
Views
635
  • Last Post
Replies
4
Views
1K
Top