Attached is a snippet of my implementation. The machine is a resource and modeled as an agent. When clicking on the rectangle, I am redirected to the agent (the resource machine). What happens in this machine is irrelevant to my problem. How can I change the color of the rectangle dynamically?
Can someone help me here? Thanks in advance.
Use the dynamic properties of the rectangle shape for its fill color.
Either check via code or use a boolean flag in your machine isOccupied
. Set it to true if someone enters, and false upon exit. Then, you can change the color as below:
A bit more complex, you need to define your own function. Switch the boolean variable from above to an integer numVisitors
. When someone enters, add to it, when someone leaves, you reduce it by 1. Create the function getMyColor(int numVisitors)
returns a Color
and take as an input the numVisitors
. You need to code the actual gradient yourself, there surely is some Java code online to help with it. Last, let your rectangle color be defined by the function as below: