Author Topic: [solved] java applet color help  (Read 3999 times)

0 Members and 1 Guest are viewing this topic.

Offline Snake X

  • Ancient Veteran
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 810
  • Rating: +33/-8
    • View Profile
[solved] java applet color help
« on: May 11, 2011, 05:32:24 pm »
So lets say I want to make a rainbow effect in a java applet.

Code: [Select]
Color rainbow = new Color(red,green,blue);

Where did the vars red green, blue come from? Lets just say they're declared random integers. That's not the important part right now.

Ok so now that I have the color 'rainbow' outside of a while/for loop, how would I change this already made color? I've tried looking for this forever but I cant find it! All I can find is Color <name> = new Color(r,g,b); nothing about changing existing colors. I can't have a color for every single value out there from 1-255 * 3 that'd be at least over 9000 color declarations.
« Last Edit: May 12, 2011, 07:57:02 pm by Snake X »
Loved this place, still the best producers of power metal, and sparked my dreams of coding.

Offline Snake X

  • Ancient Veteran
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 810
  • Rating: +33/-8
    • View Profile
Re: java applet color help
« Reply #1 on: May 12, 2011, 07:04:39 am »
anyone..?

Sorry for double posting but I didn't see any other way and I thought this thread would never get noticed if I didn't do anything :s
Loved this place, still the best producers of power metal, and sparked my dreams of coding.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: java applet color help
« Reply #2 on: May 12, 2011, 07:39:59 am »
I'm not a Java programmer, but I'll try to help you anyway.

If I understand correctly, you want to change the color of "Color rainbow"?
Well, I think you just can issue
Code: [Select]
Color rainbow = new Color(red,green,blue);again, just with other values for red,green and blue.

Edit: if Color is a type, I think you can leave it away, as the var is already declared.
« Last Edit: May 12, 2011, 07:41:43 am by jimbauwens »

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: java applet color help
« Reply #3 on: May 12, 2011, 08:55:10 am »
could you  just take out the color part for when you are changing it?
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline m1ac4

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 106
  • Rating: +8/-0
    • View Profile
Re: java applet color help
« Reply #4 on: May 12, 2011, 10:00:32 am »
A quick google search on the subject turned up this webpage.
So the code displayed that site that would generate a random 24-bit color would look like
Code: [Select]
Random r = new Random();
Color  c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));

Offline Snake X

  • Ancient Veteran
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 810
  • Rating: +33/-8
    • View Profile
Re: java applet color help
« Reply #5 on: May 12, 2011, 06:23:43 pm »
edit: I got it. Thanks for all your help :D
« Last Edit: May 12, 2011, 07:02:30 pm by Snake X »
Loved this place, still the best producers of power metal, and sparked my dreams of coding.