rect change color on click
in
Programming Questions
•
9 months ago
Hello, I have made some buttons, and I cant figure out how to make them change color when clicked, and when another button is clicked the other button will change back to it's original color.
Thanks in advance
- color selected = 150;
- void setup () {
- size (500, 350);
- textAlign(CENTER, CENTER);
- }
- void button (int nr, String text, int filter) {
- int buttonW = 70;
- int buttonH = 20;
- int buttonX = nr*(buttonW+10)-buttonW;
- int buttonY = height-(buttonH+10);
- fill (selected);
- rect (buttonX, buttonY, buttonW, buttonH);
- fill (0);
- text (text, buttonX+buttonW/2, buttonY+buttonH/2);
- }
- void draw () {
- button(1, "Button1", GRAY);
- button(2, "Button2", GRAY);
- button(3, "Button3", GRAY);
- button(4, "Button4", GRAY);
- button(5, "Button5", GRAY);
- button(6, "Button6", GRAY);
- }
1