« Scribbling on PlanetJFX | Main | Red Rubber Ball (Puzzler 2) Results and Sample Solution »

November 08, 2007

Comments

Erik

Hi Jim, good beginning exercise. Here's a version that uses the model for initialization
as well.
Erik
//

import javafx.ui.*;
import javafx.ui.canvas.*;

class RedBallModel {
attribute xi: Integer;
attribute yi: Integer;
attribute x: Integer;
attribute y: Integer;

}

RedBallModel.xi = 200;
RedBallModel.yi = 200;


var rbm = RedBallModel{
xi:200
yi: 200
x: 200
y: 200
};

Frame {
var canvas =
Canvas {
content:
Circle {
cx: bind rbm.x
cy: bind rbm.y
radius: 100
fill: red
onMouseDragged: operation(e:CanvasMouseEvent) {
rbm.x += e.localDragTranslation.x;
rbm.y += e.localDragTranslation.y;
}
}
}

title: "Red Rubber Ball"
content:
BorderPanel {
center:
canvas
top:
FlowPanel {
content: [
Button {
text: "Reset"
action:
operation() {
rbm.x=rbm.xi;
rbm.y=rbm.yi;
}
},
Button {
text: "Print"
action:
operation() {
canvas.print();
}
}
]
}
}
width: 500
height: 500
visible: true
}

Pavel

Hi Jim,

Please check my code:

/*
* RedRubberBall.fx
*/

import javafx.ui.*;
import javafx.ui.canvas.*;

class Coords {
attribute x: Integer;
attribute y: Integer;
}

var position = new Coords(){
x:200,
y:200
};

Frame {
var circle =
Circle {

cx: bind position.x
cy: bind position.y
radius: 100
fill: red

}
var canvas =
Canvas {
content:
circle
onMouseDragged: operation(e:MouseEvent) {
position.x = e.x;
position.y = e.y;
}
}
title: "Red Rubber Ball"
content:
BorderPanel {
center:
canvas
top:
FlowPanel {
content: [
Button {
text: "Reset"
action:
operation() {
position.x = 200;
position.y = 200;
}
},
Button {
text: "Print"
action:
operation() {
canvas.print();
}
}

]
}
}
width: 500
height: 500
visible: true
}

This is the first thing i do with fx besides testing the apps from the net. Thanks for the oportunity to learn something :)

The comments to this entry are closed.

Categories