Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+6 votes

I am on part C3 of Lab 4 and I was able to implement the color picker button, however, I am unsure how to make it fill the background. When digging around online I assumed all I had to do was "g.setFill(colorPicker.getValue());" But because colorPicker is not a local variable, it does not work. I declared colorPicker after the Button declaration in start(Stage stage) to have it included in the button bar. Was that incorrect? Should it be declared elsewhere?

asked in CSC 305 Fall 2024 by (660 points)

2 Answers

+4 votes
 
Best answer

I didn't do it this way, so I don't have an answer to your question, but I have another method of doing it. I chose to make a new private Color background variable which starts as dark green and updates when the colorPicker button is clicked. Then you can just draw the board again and have drawBoard() use the background variable every time.

answered by (2.8k points)
selected by
+3 votes

The declaration is correct: It is the value being transferred that is the issue. Since it is a control type (like button), it should be where the buttons are. HOWEVER, you want to get the variable that the colorPicker stores from one void function to another.

answered by (1.4k points)
...