[java] Colors in Java
How can you use red, green, and blue values to construct a single color? I mean, I''ve seen it before, a long time ago, I don''t remember where. It was where you had, say, values for r, g, and b, and you could call a method or something like that to combine those colors and set it as the current color for Java to use. I hope you understand my question!
Grant Palin
Actually, you''d be creating a Color object, so it''d be g.setColor(c). Color.name is used for default colors...
Example: Color.BLACK, g.setColor(Color.BLACK).
See, the default colors are static fields of the Color class. =)
This isn''''t life in the fast lane, it''''s life in the oncoming traffic.
-- Terry Pratchett
Example: Color.BLACK, g.setColor(Color.BLACK).
See, the default colors are static fields of the Color class. =)
This isn''''t life in the fast lane, it''''s life in the oncoming traffic.
-- Terry Pratchett
Neither of the solutions provided work for me.
M:\Comp132\ColorPicker.java:33: cannot resolve symbol
symbol : constructor Color (int,java.awt.Graphics,int)
location: class java.awt.Color
Color color = new Color(r,g,b);
M:\Comp132\ColorPicker.java:36: cannot resolve symbol
symbol : constructor Color (int,java.awt.Graphics,int)
location: class java.awt.Color
g.setColor(new Color(r,g,b));
Grant Palin
M:\Comp132\ColorPicker.java:33: cannot resolve symbol
symbol : constructor Color (int,java.awt.Graphics,int)
location: class java.awt.Color
Color color = new Color(r,g,b);
M:\Comp132\ColorPicker.java:36: cannot resolve symbol
symbol : constructor Color (int,java.awt.Graphics,int)
location: class java.awt.Color
g.setColor(new Color(r,g,b));
Grant Palin
You''re passing the Graphics object instead of the green value to the Color constructor. Try:
public void paint (Graphics g) { int red = 255; int green = 255; int blue = 255; Color color = new Color(red, green, blue); g.setColor(color); // Do your drawing commands}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement