Congratulations to Pavel for submitting the first solution to the Red Rubber Ball Puzzler, and the fact that it met the requirements of the problem. Thanks also to Erik for submitting a solution. I've actually decided to award both Pavel and Erik a JavaFX Script eBook because Erik used the localDragTranslation attribute of the CanvasMouseEvent (a technique shown in the JavaFX Canvas Tutorial). Because of this, when clicking and dragging the circle, it doesn't center the circle on the point at which the mouse was clicked (as Pavel's solution does). Again, both solutions met the requirements, and congratulations to both!
For reference, here's my sample solution:
/*
* RedRubberBallSolution.fx
*/
import javafx.ui.*;
import javafx.ui.canvas.*;
class RedBallModel {
attribute x:Integer;
attribute y:Integer;
}
Frame {
var model =
RedBallModel {
x: 200
y: 200
}
var canvas =
Canvas {
content:
Circle {
cx: bind model.x
cy: bind model.y
radius: 100
fill: red
onMouseDragged: operation(cme: CanvasMouseEvent) {
model.x += cme.localDragTranslation.x;
model.y += cme.localDragTranslation.y;
}
}
}
title: "Red Rubber Ball Solution"
content:
BorderPanel {
center:
canvas
top:
FlowPanel {
content: [
Button {
text: "Reset"
action:
operation() {
model.x = 200;
model.y = 200;
}
},
Button {
text: "Print"
action:
operation() {
canvas.print();
}
}
]
}
}
width: 500
height: 500
visible: true
}
By the way, I am trying to submit these puzzlers at different times of the day so that everyone gets a fair chance at some point of actually being awake when one is submitted. Insomniacs, of course, have a big advantage ;-)
Regards,
Jim Weaver
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications
Comments