pls help me display random color in swing
Display Random Color in Swing
Page 1 of 19 Replies - 4345 Views - Last Post: 06 August 2010 - 09:01 PM
Replies To: Display Random Color in Swing
#2
Re: Display Random Color in Swing
Posted 06 August 2010 - 10:42 AM
You'll have to post some code in order to demonstrate that you've actually tried this and are looking for guidance.
My guess:
Get random number.
Retrive a Color variable from a Color[] array using the random number generated.
My guess:
Get random number.
Retrive a Color variable from a Color[] array using the random number generated.
#3
Re: Display Random Color in Swing
Posted 06 August 2010 - 10:47 AM
Color constructor takes three integers (R,G,B ) so what you need is (randomValue1, randomValue2, randomValue3).
This post has been edited by Mercurial: 06 August 2010 - 10:48 AM
#4
Re: Display Random Color in Swing
Posted 06 August 2010 - 10:59 AM
Topic renamed to be more descriptive. Please respect rule #4 of this forum. "Java" is not a descriptive title in a forum dedicated to Java.
What have you tried? Can you show us your good faith efforts? What specific problems are you having?
What have you tried? Can you show us your good faith efforts? What specific problems are you having?
#5
Re: Display Random Color in Swing
Posted 06 August 2010 - 11:13 AM
One way to get a truly (in theory) random color and avoids arrays:
Random r = new Random(); Color randomColor = new Color(r.nextInt(256),r.nextInt(256),r.nextInt(256));
#6
Re: Display Random Color in Swing
Posted 06 August 2010 - 03:15 PM
Or just do
Color c = new Color((int)(Math.random() * 0xFFFFFF));
#7
Re: Display Random Color in Swing
Posted 06 August 2010 - 03:17 PM
What does 0xFFFFFF mean?
#8
Re: Display Random Color in Swing
Posted 06 August 2010 - 03:30 PM
#9
Re: Display Random Color in Swing
Posted 06 August 2010 - 04:12 PM
If you see a number prefaced with 0x, that is a hexadecimal literal. A number prefaced with 0 is an octal literal. With Java 7, we get binary literals as well.
#10
Re: Display Random Color in Swing
Posted 06 August 2010 - 09:01 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|