| Author |
Array of colors in paintComponent method.
|
Jonathan Haybok
Greenhorn
Joined: Mar 12, 2009
Posts: 16
|
|
I can't seem to figure out how to fill the polygons I made with random colors. My assignment specifically says to generate 10 random colors, use an array to store the 10 colors and then use the colors to fill the ten polygons I made. Right now my array seems to just hold numbers between 0 and 255, and I don't know how I would set up the 10 RGB sets.
Lines 57 to 66 is where the specific code is.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
setColor expects a java.awt.Color object. What I might do is generate 3 random #'s 10 times. One for each: Red, Green, and Blue. I'd have a java.awt.Color[] and populate it with 10 Color objects.
Then do your page.setColor(color[index]);
|
 |
Jonathan Haybok
Greenhorn
Joined: Mar 12, 2009
Posts: 16
|
|
I wrote this out, and get this: "AWT-EventQueue-0" java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue"
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
Check the API. It tells you what kinds of arguments the Color constructor takes. Here's a hint, you can't mix int's and float's.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
|
Sounds like a Swing-related topic. Moving.
|
 |
Jonathan Haybok
Greenhorn
Joined: Mar 12, 2009
Posts: 16
|
|
Seems like I'm missing something here...
I tried changing them to floats, but then that was incompatible. So I tried this other format, which doesn't work.
ERROR: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 9
|
 |
 |
|
|
subject: Array of colors in paintComponent method.
|
|
|