wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes ColorTable Array!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ColorTable Array!!" Watch "ColorTable Array!!" New topic

ColorTable Array!!

Justin bob

Joined: Nov 07, 2005
Posts: 3
ok I'm doing a color table array, it displays 100x20 rectangles(256 of them) with 256 shades of green, blue, or red. My name is printed in the very top left had rect. and the rest are also numbered.

im having a problem getting all the numbers to show up...
here is my code....

if anyone can help, i would appreciate it.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38107
I'm not very familiar with applets, but I shall have a go.

Actually when I tried running your code, the numbers appeared nice and clear in yellow, but I couldn't see the coloured rectangles; the whole background was black. Why are you using the same identifier for your class as your Color[] array? Use a different name, to avoid confusion.

You don't need the several for loops; you can combine them into one, and it is a good idea not to use a number in the middle. Also you don't need to use i as a field, so you get:

BUT you don't really nead Rcolor Bcolor or Gcolor at all.
You can simplify it to something on the lines of

You do realise that the first three colours will be completely black, and there will be no green or blue to them until no 33? In fact the brightest colour will be (85, 7, 7), which is about the same colour as a bar of plain chocolate. Is that what you intended?

In your paint() method, why have you get x and y? You don't actually seem to use them. You don't seem to use h and w, either. Can you get rid of them?
And you seem to be setting one of them to i%32. Why?

I am not quite sure what you are doing with the rectangles; they seem to be falling off the right side of the view.

Try what I have suggested, and see whether that makes it any better.

[ November 07, 2005: Message edited by: Campbell Ritchie ]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38107
Did you get it to work?
It is sorta covered in the JavaRanch Style Guide.
subject: ColorTable Array!!
Similar Threads
Why does it not show the new coordinates?!!??!!
Problem painting component
Colour picker, MouseDown(Event, int x, int y) Depreciation Help!
Null Pointer Exception Error - .contains(p)
Getting the TwoButtons to add the gradient circle to the panel