I need to carry out an assignment statement in my applet which is a colour picker. There is a grid of 12 coloured buttons and when you click one I want it to assign that colour to a public colour named current colour. So then I will be able to set the background or text of something else to whatever the current colour is.
The way I did it with numbers was to have a
public int currentnumber at the top and then I used
if (e.getSource()==b1) currentnumber =1;
this is what I want to do only instead of numbers to use colours.
like I said i'm probably missing something really simple but i'd appreciate any help
thanks in advance
03-27-2003, 04:33 PM
Fantik
post your code, or at least what you have so far.
use code blocks please.
04-04-2003, 03:14 PM
MasterOfSouls
If you want to store which color it is after the user clicks the button as the color name, you could do this... at the beginning of the code declare a string (String colorName) and then when you have the source of the event, instead of saying currentnumber = 1, put colorName = "red":
if (e.getSource()==b1) colorName = "red";
When you need to find out what color is chosen later on, you can use the compareTo function, like this:
if (colorName.compareTo("red") == 0) {
//The color is red
}
else if (colorName.compareTo("blue") {
//the color is blue
}