In most GUI frameworks, the result of fiddling with a widget (pushing a button, moving a slider, etc.) generates an event. These events are either handled by a listener (in the Java model) or a callback (in a number of other languages). A callback, so you know, is nothing more than a function that is called when the widget is fiddled with.
For example, I have written function called red-callback.
(define (red-callback slider-widget an-event)
(let ([slider-value (send slider-widget get-value)])
(send the-model set-red-value! slider-value)
))
My callback takes two arguments: the slider object itself, and the event object. Sometimes, we need data contained within the event object; this time, we do not. The slider object, however, has a lot of useful information (documentation). Among other things, we can get the value of the slider by invoking its get-value method.
So, the red-callback gets the value of the slider, and then updates the model using that information. That is ALL it does.
To update the controller, you need to do two things:
- Create two new callbacks called green-callback and blue-callback. These should call the appropriate setters in the model.
- Create two new slider objects, and attach them to the frame. They will be very, very similar to the red slider, but you should attach the appropriate callback function to each one. That is, the green slider should use the green-callback function, and so on.
Your code should be executable at this point, and it should be done! I'd like to see your application functioning before you head out the door.